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); Link to comment https://forums.phpfreaks.com/topic/21551-pass-submit-button-values-to-javascript/ 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] Link to comment https://forums.phpfreaks.com/topic/21551-pass-submit-button-values-to-javascript/#findComment-96175 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. Link to comment https://forums.phpfreaks.com/topic/21551-pass-submit-button-values-to-javascript/#findComment-96199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.