Thursday, December 6, 2012

How to remove or cancel onsubmit event in java script

This kind of situation we may get when we work with javascript methods.In my application the dynamic java script onsubmit event has been used to form for validation .Based on requirement i need to add the onclick event on submit button in form.So the problem here is ,when i click on the button the form onsubmit event also fired.Because of that i can't insert the valid data in to data base.
To resolve this i just do the onsubmit function return false.then then will stop that event when i click on button.
function validatecheck()
{
var rad=document.getElementById('OR');
if(radi.checked)
{
var vali=document.getElementById('OT').value;
if(val=="")
{
alert('Please enter value');
document.getElementById('frmres').onsubmit = function() {
return false;
}
}
else
{
document.getElementById('frmres').onsubmit = function() {
return dynamicvalidation();
}
}
}
}

No comments:

Bel