Jump to content


This topic is now archived and is closed to further replies.


Pass submit button values to javascript

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

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

Here is the submit button code:
<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'>

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

var a_action = document.my_account.account_action.value;


Share this post

Link to post
Share on other sites
the problem is that you have all three buttons named identically, so there is no way to reference them. you need to name them appropriately, and then you can reference them as you are attempting with:

Share this post

Link to post
Share on other sites


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.