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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form - Multiple buttons - Which one pressed?

Status
Not open for further replies.

activethistle

Technical User
Apr 3, 2001
95
0
0
GB
I have a form with about 150 buttons on it. How do I determine which one has been pressed? They all have names like b1, b2, b3 etc...
I guess document.forms(0).elements comes into it somewhere?

TVMIA FYH

Active


 
Try this:

<form name=&quot;update&quot;>

<INPUT TYPE=&quot;button1&quot; NAME=&quot;perform&quot; ONCLICK='document.update.whichbutton.value=1;document.update.submit()' value=&quot;Button1&quot;>
<INPUT TYPE=&quot;button2&quot; NAME=&quot;perform&quot; ONCLICK='document.update.whichbutton.value=2;document.update.submit()' value=&quot;Button2&quot;>

<input type=Hidden name=&quot;whichbutton&quot; value=&quot;&quot;>

</form>

Then all have to repeat the number of buttons to 150. And then on the next page just reference the value for
whichbutton and you will get the corresponding value.

Richard
 
Hi,

I think this is a bit shorter:

<html>
<head>
<title>150buttons</title>
<script>
function dataval(no) {
document.form1.whichbut.value=no;
document.form1.submit();
}
</script>
</head>

<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;&quot;>
<br>
<input type=&quot;hidden&quot; name=&quot;whichbut&quot;>
<br>
<input type=&quot;button&quot; name=&quot;Button&quot; value=&quot;0&quot; onclick=&quot;dataval(0);&quot;>
<input type=&quot;button&quot; name=&quot;Submit2&quot; value=&quot;1&quot; onclick=&quot;dataval(1);&quot;>
<input type=&quot;button&quot; name=&quot;Submit3&quot; value=&quot;2&quot; onclick=&quot;dataval(2);&quot;>
<input type=&quot;button&quot; name=&quot;Submit4&quot; value=&quot;3&quot; onclick=&quot;dataval(3);&quot;>
<input type=&quot;button&quot; name=&quot;Submit5&quot; value=&quot;4&quot; onclick=&quot;dataval(4);&quot;>
<br>
<input type=&quot;button&quot; name=&quot;Submit6&quot; value=&quot;5&quot; onclick=&quot;dataval(5);&quot;>
<input type=&quot;button&quot; name=&quot;Submit7&quot; value=&quot;6&quot; onclick=&quot;dataval(6);&quot;>
<input type=&quot;button&quot; name=&quot;Submit8&quot; value=&quot;7&quot; onclick=&quot;dataval(7);&quot;>
<input type=&quot;button&quot; name=&quot;Submit9&quot; value=&quot;8&quot; onclick=&quot;dataval(8);&quot;>
<input type=&quot;button&quot; name=&quot;Submit10&quot; value=&quot;9&quot; onclick=&quot;dataval(9);&quot;>
</form></body></html>

Continue the <input> tag until 150 buttons with the same format and in your receiving code evaluate variable whichbut to determine which button is being clicked.

Regards,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top