Solved

Javascript type=button

Posted on 2006-06-23
7
256 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
AlarmClock Challenge 35 155
HTML5 vs JSP - REST based application development 4 1,204
mask rule in struts validation.xml 5 94
eclipse buid path vs tomcat lib path 10 34
This article describes how to reset your Windows 10 password when you've forgotten it.
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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