Solved

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

Posted on 2003-11-25
12
384 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 125 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

738 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