[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Javascript type=button

Posted on 2006-06-23
7
Medium Priority
?
267 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 28

Assisted Solution

by:rrz
rrz earned 1000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 28

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

Independent Software Vendors: 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

Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
Moore’s Law has proven itself time and time again since it was first introduced. So what’s next? Will Moore’s law continue to remain relevant, or will new technology take over and bring us the next big advancement in computing?
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 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