Solved

Javascript type=button

Posted on 2006-06-23
7
259 Views
Last Modified: 2010-04-01
How do I know if anyone clicked on the button or submit

<input type=button name=action value="Previous">
<input type=submit name=action value="next">

If I made the upper all type=submit, then I can know by the value of "action",

But for the button, I can't seem to get the value of action, it seems value of action is null? Then how can I know which button the customer clicked?

Thanks.
0
Comment
Question by:xiaoyunwu
[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
  • 3
  • 2
  • 2
7 Comments
 
LVL 3

Expert Comment

by:aflat362
ID: 16972193
Make 2 different forms with two different actions.

So if you are doing servlets, have 2 different servlets NextServlet and PreviousServlet

Or struts, have 2 different Action classes.

This is probably the easiest way to do it.
0
 

Author Comment

by:xiaoyunwu
ID: 16972224
I'm using the same form information. I don't want to made them into two forms. Thanks.
0
 
LVL 27

Assisted Solution

by:rrz
rrz earned 250 total points
ID: 16972290
The button doesn't call any function. You could just use
<input type=submit name=action value="Previous">
<input type=submit name=action value="next">  
or you could call a function  
<input type=button name=action value="Previous" onClick="doSomethingAndSubmit();">
<input type=submit name=action value="next">
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:aflat362
ID: 16972313
In the above example, doSomethingAndSubmit function
could set the value of a hidden field.


Example

you have a hidden field in your form called "direction" - default it to next.

<input type="hidden" name="direction" value="next">

In Function before submitting, if called from "previous"  set the value of the hidden field to "previous"

In your servlet, read the value of "direction" you'll know if it was "next" or "previous"
0
 

Author Comment

by:xiaoyunwu
ID: 16972408
I'm using BroadVision, and I used the method as you said and set the hidden value, in the browser I know the value was set, but the server didn't get the value. And I didn't want to use two type=submit since I want customer able to hit enter and automatically submit "next" for them, instead of submit "previous" for them, and "previous" button has to be on the left side.

I guess, I will just let server say if "action" is null then
action= "previous"
0
 
LVL 27

Expert Comment

by:rrz
ID: 16972490
afat362's  idea of hidden parameter is good. Show your code if you want us to help you make it work.
0
 
LVL 3

Accepted Solution

by:
aflat362 earned 250 total points
ID: 16972534
rrz@ - thanks for the props.  your post gave me the idea

Just to clarify if it wasn't clear  (I didn't check syntax but this should be very close)

<script language="javascript">
function doPrevious(){
  yourForm.direction.value="previous";
  yourForm.submit();
}
</script>

<form name="yourForm" method="post" action="someServlet">
  <input type="hidden" name="direction" value="next">
  <input type="button" name="previous" value="previous" onClick="javascript:doPrevious()">
  <input type="submit name="next" value="Submit">
</form>


////////
In your servlet doPost:

String direction = request.getParameter("direction");

if(direction.equals("previous")){
   //handle accordingly.
}
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

687 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