...

View Full Version : button identification??



wisemind85
03-11-2009, 09:13 PM
I have 3 buttons on the page and each has type of submit.So how we can identify on other page which one button is clicked??

Philip M
03-12-2009, 08:21 AM
I have 3 buttons on the page and each has type of submit.So how we can identify on other page which one button is clicked??

Cookie.

Within the same page:-


<script type="text/javascript">
var buttn;
function whichBtn(frm) {
alert(buttn);
return false;
}
</script>

<form name = "myform" onsubmit="return whichBtn(this)">
<input type="image" src="http://www.codingforums.com/images/buttons/reply.gif" border="0" name="Post Reply" onclick="buttn=this.name">&nbsp;&nbsp;

<input type="image" src="http://www.codingforums.com/images/buttons/quote.gif" border="0" name="Quote" onclick="buttn=this.name">
</form>


He thought he saw a Garden-Door
That opened with a key:
He looked again, and found it was
A Double Rule of Three:
"And all its mystery," he said,
"Is clear as day to me!"
- Lewis Carroll

abduraooft
03-12-2009, 08:29 AM
So how we can identify on other page which one button is clicked??


<form name = "myform" method="get">
<input type="submit" name="Reply" value="Reply" >&nbsp;&nbsp;

<input type="submit" name="Quote" value="Quote">
</form>
Check the url after submitting a form like above.

wisemind85
03-12-2009, 10:39 PM
Well the thing that i want is.

I have 3 buttons with ids b1,b2,b3

<form name='form1' action='abc.jsp'>
<input type='Submit' value='b1' id='b1'/>
<input type='Submit' value='b2' id='b2'/>
<input type='Submit' value='b3' id='b3'/>

</form>

So i want to get the value of button on jsp page using javascript that which one button was clicked,Do you think i have to define some hidden variable?? Any solution??

Eldarrion
03-12-2009, 11:02 PM
You don't have to define any hidden variables. Just add a name to the submits the way abduraooft suggested as well as changing the form method to get, you can even go as far as to give them all the same name. example:



<form name='form1' action='abc.jsp' method="get">
<input type='Submit' value='b1' id='b1' name="which"/>
<input type='Submit' value='b2' id='b2' name="which"/>
<input type='Submit' value='b3' id='b3' name="which"/>
</form>


After that... getting the value from JSP shouldn't be all that hard:



<%
String which = request.getParameter("which");
%>


After that... just do whatever with the variable which (that contains the value of the clicked button). I don't see where the problem is with the offered solutions.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum