PDA

View Full Version : Simple form validation question



beedie
04-24-2008, 07:48 AM
I have a form that is submitted by a button that calls an ajax request. I want that same button to have another onclick event that checks the form is valid. How do i do it? New to javascript obviously. :confused:
This the button now:


<input type="BUTTON" onclick="ajaxFunction()" value="ADJUST">

rangana
04-24-2008, 07:50 AM
<input type="BUTTON" onclick="ajaxFunction();validateFunction();" value="ADJUST">

beedie
04-24-2008, 08:18 AM
That was very good but the ajaxFunction gets called once the user clicks ok that the fields are empty
the ajaxFunction simply calls this function for each field:


function isEmpty(elem, helperMsg){
if(elem.value.length == 0){
alert(helperMsg);
elem.focus();
return true;
}
return false;
}

so the server side code gets executed whether it is valid or not. I need the ajaxFunction to be called only if validation is TRUE.

abduraooft
04-24-2008, 08:33 AM
Then simply change the order of calling of these two functions Or call the second function at the end of the other's body.