?
Solved

want to differentiate the button clicks from a single page using javascript.....

Posted on 2003-11-25
12
Medium Priority
?
390 Views
Last Modified: 2008-03-17
Dear experts,

I need to have many buttons in a page and thinking of doing different actions on the individual button clicks.Say for example, i have a search screen from which different criteria options are displayed.For each criteria one button is used to submit the criteria separately.i use single form and all submit buttons.But in the processing servlet i am not able to differentiate the button clicks and the corresponding parameters.i want a solution to solve this issue.somehow i felt javascript would be of my help.But i could not get the correct script for implementing this.Can any expert would heed to help me?
thanks in advance
sat
0
Comment
Question by:sathiyam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +2
12 Comments
 
LVL 8

Expert Comment

by:xabi
ID: 9818040
Hi torbjornfahlen,

Here goes an example

<html>
<head>
</head>
<body>
<form action="put_here_your_action_page" method="GET" name="myform">
Field1: <input type="text" value="" name="field1">
<br><input type="button" value="Option1" onclick="this.form.action.value='option1';this.form.submit()">
<br><input type="button" value="Option2" onclick="this.form.action.value='option2';this.form.submit()">
<br><input type="button" value="Option3" onclick="this.form.action.value='option3';this.form.submit()">
<input type="hidden" name="action" value="">
</form>
</body>
</html>


xabi
0
 
LVL 8

Expert Comment

by:xabi
ID: 9818054
As you can see the info about the burron is in the field "action"

xabi
0
 
LVL 2

Expert Comment

by:DidierD
ID: 9818070
You can do it like this

<script>
  function gotoCancel(){
    document.yourForm.action="nextPage1.do";
    document.yourForm.submit();
  }

  function gotoOK(){
    document.yourForm.action="nextPage2.do";
    document.yourForm.submit();
  }
 
  function gotoSomething(param){
    document.yourForm.action="nextPage3.html?param=" + param;
    document.yourForm.submit();
  }

</script>


<input type="button onClick="goToCancel()">
<input type="button onClick="gotoOK()">
<input type="button onClick="gotoSomething(param1)">
<input type="button onClick="gotoSomething(param2)">


Greetz,
Didier
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 10

Expert Comment

by:NetGroove
ID: 9818080
Or you let your buttons be Submit buttons, give them all the same name, elt say "Submit" and assign to every button a different value according to requested action.
Like this:

<form action="yourpage.jsp">
<input type=submit name="Submit" value="new">
<input type=submit name="Submit" value="mod">
<input type=submit name="Submit" value="del">
</form>

On server side you check the button like other form elements for its value to see the submitted value: Submit == "mod"

0
 
LVL 8

Expert Comment

by:xabi
ID: 9818098
NetGroove, you are right, the only problem is the "lavel" of the button ....  It must be the same as the text to be checked at the server side.

xabi
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 9818125
do not name the submit, or you may run into problems
0
 

Author Comment

by:sathiyam
ID: 9818127
hi xabi,
is there a way to use object id of an html element and identify the element and process the click?
sat
0
 
LVL 10

Expert Comment

by:NetGroove
ID: 9818159
I named it Submt.
That name provoke NO problems.

0
 
LVL 8

Expert Comment

by:xabi
ID: 9818181
This way?

<html>
<head>
<script>
function go(sName) {
  alert("You clicked " + sName + " id button");
  document.myform.action.value = sName;
  document.myform.submit();
}
</script>
</head>
<body>
<form action="put_here_your_action_page" method="GET" name="myform">
Field1: <input type="text" value="" name="field1">
<br><input id="id1" type="button" value="Click for action 1" onclick="go(this.id)">
<br><input id="id2" type="button" value="Click for action 2" onclick="go(this.id)">
<br><input id="id3" type="button" value="Click for action 3" onclick="go(this.id)">
<input type="hidden" name="action" value="">
</form>
</body>
</html>
0
 
LVL 8

Accepted Solution

by:
xabi earned 500 total points
ID: 9818207
Even better:

<html>
<head>
<script>
function go(oButton) {
  alert(oButton.form.name);
  alert("You clicked '" + oButton.id + "' id button");
  oButton.form.action.value = oButton.id;
  oButton.form.submit();
}
</script>
</head>
<body>
<form action="put_here_your_action_page" method="GET" name="myform">
Field1: <input type="text" value="" name="field1">
<br><input id="id1" type="button" value="Click for action 1" onclick="go(this)">
<br><input id="id2" type="button" value="Click for action 2" onclick="go(this)">
<br><input id="id3" type="button" value="Click for action 3" onclick="go(this)">
<input type="hidden" name="action" value="">
</form>
</body>
</html>
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10383703
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: xabi {http:#9818207}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question