Form validation - prevent certain buttons firing

N

Nick Bell

I have a general form validation question. I know very little about
javascript, a little more about PHP. Using yav (http://yav.sourceforge.net):

<form method="POST" name=edit onsubmit="return performCheck('edit', rules,
'classic');" action="pages_edit_submit.php">
<input type="text" name="title">
<input type="submit" name="Save">
<input type="submit" name="Cancel">
</form>

.... PerformCheck fires when any submit button is click, which is logical but
I'd like to prevent this if it was the cancel button that was clicked (and
preserve form submission on pressing Enter whilst in the 'title' box.

Very many thanks

Nick
 
N

Nick Bell

Self answering question.

I'd like to prevent this if it was the cancel button that was clicked (and
preserve form submission on pressing Enter whilst in the 'title' box.

Declare another variable e.g. Var canc=false
In the onclick bit of the button you don't want to trigger the validation
routine insert "canc=true;"
In the onsubmit bit of <form> insert "return (performCheck() or canc);"

Apologies for holding you up, hope the solution helps someone in the future

Nick
 
R

RobG

Nick said:
I have a general form validation question. I know very little about
javascript, a little more about PHP. Using yav (http://yav.sourceforge.net):

<form method="POST" name=edit onsubmit="return performCheck('edit', rules,
'classic');" action="pages_edit_submit.php">
<input type="text" name="title">
<input type="submit" name="Save">
<input type="submit" name="Cancel">
</form>

.... PerformCheck fires when any submit button is click, which is logical but
I'd like to prevent this if it was the cancel button that was clicked (and
preserve form submission on pressing Enter whilst in the 'title' box.

If you don't want the 'cancel' button to submit, don't make it a
submit button. Presumably you want to run the validation but not
submit the form, so why not just use a plain button with a
appropriate label?

<input type="button" value="Check form" onclick="
performCheck('edit', rules,'classic');
">
 

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,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top