Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

button value

Status
Not open for further replies.

parames

MIS
Jun 26, 2000
71
MY
Hi list,
How to get the submit button value in javascript. For example,my code looks like this:
-------------
response.write form method=post name=theform action='picking_edit2.asp' onsubmit='return chk_submit_bottom()'>"
------------

response.write &quot;<tr><input type=submit name=button value='Edit'> <input type=submit name=button value='Delete'> <input type=reset value='Reset'>&quot;
-------------

Once user submit this page, i want to check which button they have choosed in javascript. How to do this..Please help. urgent..

Thanks a lot..

Best Regards,
Parames.S
 
buttons in javascript you want to fetch a value from need ID tags as well as a name tag,

other suggestions:

1. use input type images, and use map ranges for the different values.

2. guessing you're checking the button value in order to determine if you want a 'are you sure you wish to delete' kind of message, just do a onclick=&quot;if(return(alert('you wish to delete?');) {form.submit();}&quot;
 
give your submit buttons names and then on your action page check if form element with such name exists
Code:
response.write &quot;<tr><input type=submit name=button value='Edit' name='btnEdit'> <input type=submit name=button value='Delete' name='btnDelete'> <input type=reset value='Reset'>&quot;
*************************
If Request.Form(&quot;btnEdit&quot;) = &quot;Edit&quot; Then
'edit button pressed
ElseIf Request.Form(&quot;btnDelete&quot;) = &quot;Delete&quot; Then
'delete button pressed
End If

When you submit form using submit button it will be available in Request scope... if you have more than one submit button on your form the only button that was used to submit your form will exist in Request scope

OR

you can use Java Script to populate a hidden form element with action and then check it on your action page but then you need to make your submit buttons input type=&quot;button&quot; and have onClick event for each ...

Code:
<form method=post name=theform action='picking_edit2.asp'>
<input type='button' value='Delete' onClick='validate_form(&quot;delete&quot;)'>
<input type='button' value='Edit' onClick='validate_form(&quot;edit&quot;)'>
<input type='hidden' name='action' value=''>
</form>

function validate_form(action)
{
if yourvalidation passed
{
document.theform.action.value = action;
document.theform.submit();
}
}

then on your action page check for Request.Form(&quot;action&quot;) value

Sergei
 
OOPS!! i forgot something, in order to reference the values of the form the form needs a name/id tag as well <Form name='theform' action...... etc>

cause you either need to do onsubmit='validate_form(this);'

using 'this' to pass the form object without a name, OR have to refer to the document element (form) directly as in :

document.theform.button1.value();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top