By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,982 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,982 IT Pros & Developers. It's quick & easy.

Need Javascript Advice

P: n/a
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

Jan 18 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
am****@iwc.net wrote:
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
Jan 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.