Need Javascript Advice

A

amerar

Hi All,

Here is my situation: I have a form where the user can perform a
number of tasks. One of these tasks is to enter a new record. The
form has an 'onsubmit' property to validate the data if the users
enters a new record.

However, there is also a button to allow the user to 'duplicate' a
stored record. In that case, I do not want to perform the entire
validation since most of the data will be fetched from the database
behind the scene. But, when the form submits, the 'onsubmit' property
takes off and attempts to validate the form......

What is the best way to handle this? Basically different behaviors
when the form is submitted??

I'm not a good Javascript programmer, so explaining throughly would
really help.

Thanks,

Arthur
 
T

Thomas 'PointedEars' Lahn

Here is my situation: I have a form where the user can perform a
number of tasks. One of these tasks is to enter a new record. The
form has an 'onsubmit' property to validate the data if the users
enters a new record.

Actually, the `form' element has an intrinsic event handler attribute
for handling its `submit' event, named `onsubmit'.
However, there is also a button to allow the user to 'duplicate' a
stored record. In that case, I do not want to perform the entire
validation since most of the data will be fetched from the database
behind the scene. But, when the form submits, the 'onsubmit'
property takes off and attempts to validate the form......

What is the best way to handle this? Basically different behaviors
when the form is submitted??

You need to find out which submit button was activated. The following
example should be self-explaining:

<script type="text/javascript">
function validate(f)
{
if (f && arguments.callee.submit.name != "duplicate")
{
// perform validation, return `false' if the result is negative
}

return true;
}
validate.submit = {};
</script>

<form ... onsubmit="return validate(this);">
...
<input type="submit" value="Submit"
onclick="validate.submit = this;">
<input type="submit" name="duplicate" value="Duplicate"
onclick="validate.submit = this;">
</form>


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top