Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average.
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-11-2009, 09:13 PM   PM User | #1
wisemind85
New to the CF scene

 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
wisemind85 is an unknown quantity at this point
button identification??

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??
wisemind85 is offline   Reply With Quote
Old 03-12-2009, 08:21 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by wisemind85 View Post
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:-

Code:
<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
Philip M is offline   Reply With Quote
Old 03-12-2009, 08:29 AM   PM User | #3
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
So how we can identify on other page which one button is clicked??
Code:
<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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 03-12-2009, 10:39 PM   PM User | #4
wisemind85
New to the CF scene

 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
wisemind85 is an unknown quantity at this point
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??
wisemind85 is offline   Reply With Quote
Old 03-12-2009, 11:02 PM   PM User | #5
Eldarrion
Regular Coder

 
Join Date: Feb 2009
Location: Wheeling, IL
Posts: 358
Thanks: 5
Thanked 62 Times in 60 Posts
Eldarrion is on a distinguished road
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:

Code:
<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:

Code:
<%
    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.
Eldarrion is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:04 AM.


Advertisement
Log in to turn off these ads.