Solved

Javascript type=button

Posted on 2006-06-23
7
253 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
loop through list of objects 14 186
Images won't display in JSP pages 30 176
bean mapper frameworks 5 56
struts hibernate integration example 28 113
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

707 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

13 Experts available now in Live!

Get 1:1 Help Now