Solved

Javascript type=button

Posted on 2006-06-23
7
254 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
  • 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Facing problems with you memory card? Cannot access your memory card? All stored data, images, videos are lost? If these are your questions...than this small article might help you out in retrieving your lost or inaccessible data.
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now