Jump to content


Photo

Pass submit button values to javascript


  • Please log in to reply
2 replies to this topic

#1 yrrahxob

yrrahxob
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationKaty, Texas

Posted 21 September 2006 - 05:38 PM

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);
Harry R. Box
[br]We must all hang together or we shall surely hang separately.
[br]
[br]A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 21 September 2006 - 06:01 PM

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:
document.formName.buttonName.value

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 yrrahxob

yrrahxob
  • Members
  • Pip
  • Newbie
  • 9 posts
  • LocationKaty, Texas

Posted 21 September 2006 - 06:31 PM

Thanks a lot.  That worked perfectly.  I really appreciate the help.
Harry R. Box
[br]We must all hang together or we shall surely hang separately.
[br]
[br]A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed."




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users