Simulating a button click

W

Wojtek

Given the following somewhat abbreviated code:
------------------------------------------
<table>

<form name="aForm1" action="doStuff" method="post">
<input type="hidden" name="id" value="1">
<tr onClick="aForm1.myButton.value='View'; aForm1.submit();">
<td>
<input type="submit" name="myButton" value="View">
<input type="submit" name="myButton" value="Edit">
</td>
<td>Value 1</td>
</tr>
</form>

<form name="aForm2" action="doStuff" method="post">
<input type="hidden" name="id" value="2">
<tr onClick="aForm2.myButton.value='View'; aForm2.submit();">
<td>
<input type="submit" name="myButton" value="View">
<input type="submit" name="myButton" value="Edit">
</td>
<td>Value 2</td>
</tr>
</form>

</table>
------------------------------------------

If I click on the View button, then the form gets submitted, and the
form handler reads that the value of myButton as 'View"

But if I click on the row, then no value for the myButton gets passed
to the form handler.

I did try aForm1.myButton[0].value='View'

How do I get the form submit to set the passed value of myButton to
'View'?
 
W

Wojtek

Michael White wrote :
... onclick="document.aForm1.myButton.value= 'View' ">

Yes, I do have the 'document.' before each element call. I trimmed it
from the example because it causes a word wrap, and it is more readable
without the word-wrap :)
 
W

Wojtek

Wojtek wrote :

Hmmm, just read the HTML spec on buttons.

The HTML spec states that if a form has multiple buttons, then only the
clicked button's value will be processed and sent to the CGI.

So if NO button is clicked by the user, then no button value is sent to
the CGI.

I would prefer not to use a hidden field for a shadow button value as
that adds another thing to be proccessed by the CGI. And it is not
"elegant" enough....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top