Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two functions off onclick not working...stumped. 1

Status
Not open for further replies.

Fingerprint

Programmer
Oct 21, 2002
35
GB
I've got the fun job of writing a form that uses entirely client-side programming for validation and input saving, as it's going out to use on disk. All the workings are written in javascript, and I know the functions work on their own, but then I get to the end:

Code:
<td><input type=&quot;button&quot; value=&quot;Save entry&quot; name=&quot;Submitbutton&quot; onClick=&quot;return validateForm(form1);save(form1);&quot; style=&quot;background-color:#F0F8FF;border-color:#B0E0E6;&quot; title=&quot;Save this entry and move on to next employee.&quot;></td>

and the validation works, but not the save! The form is huge, (there are 61 fields), so I'm reluctant to post it all unless necessary. If I remove the 'return' from before the validateForm, both functions fire, but when I put it back only the validation works.
I made sure there's an
else
return true
at the end of the validation function, but it isn't working!

Any ideas why? Please?

 
the handler for the submission of the form (onSubmit) is like a function that looks like this :

function onClick()
{
return validateForm(form1);
save(form1);
}

The problem is that when you do a return inside a function it stops from executing at that moment.

so what you would need to do is this :

function onClick()
{
save(form1);
return validateForm();
}

or maybe :

function onClick()
{
if (validateForm())
{
save(form1)
}
else
{
return false;
}
}

you can put it all inside the hanlder like so :

onclick=&quot;if(validateForm()){ save(this) }else{ return false }&quot;

I hope this helps. Gary Haran
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top