yrrahxob Posted September 21, 2006 Share Posted September 21, 2006 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 helpThank youHarryHere 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'> <input type='submit' name='account_action' value='Delete'> <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); Quote Link to comment Share on other sites More sharing options...
obsidian Posted September 21, 2006 Share Posted September 21, 2006 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:[code]document.formName.buttonName.value[/code] Quote Link to comment Share on other sites More sharing options...
yrrahxob Posted September 21, 2006 Author Share Posted September 21, 2006 Thanks a lot. That worked perfectly. I really appreciate the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.