Jump to content

Pass submit button values to javascript


yrrahxob

Recommended Posts

I have a form that has three submit buttons and when I submit the form it goes through a validation routine to verify that all fields contain valid data.  What I want to do is bypass the validation routine if the user selects "Delete" or "Cancel" on the form.  Is there a way to get the value of the submit button in javascript?  Below is the code I have written but the alert I put in the script to show the value of the submit button is "Undefined".  Please help

Thank you
Harry

Here is the form code:
<form name=my_account action=index.php method=post onsubmit='return account_validate()'>

Here is the submit button code:
<tr>
<td align='left' colspan='2'>
<input type='submit' name='account_action' value='Update'>&nbsp;&nbsp;&nbsp;
<input type='submit' name='account_action' value='Delete'>&nbsp;&nbsp;&nbsp;
<input type='submit' name='account_action' value='Cancel'>
</td>
</tr>

Here is the javascript function code:
function account_validate() {

var a_action = document.my_account.account_action.value;

alert(a_action);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.