wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Identifying the submit button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Identifying the submit button" Watch "Identifying the submit button" New topic
Author

Identifying the submit button

Aj Manch
Ranch Hand

Joined: May 07, 2001
Posts: 50

This is a simple HTML and JavaScript question. I have multiple submit buttons on a form. Based on which button was clicked I would like to show a different message to the user. Can anybody tell me how to do that?
Thanks in advance,
Aj
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

I dont have a complete answer. I know you can give each button a name. I dont know how to use javascript to do what you want though(im not an expert at js). You can also use input type=button instead of type=submit if necessary. that about all i know. i hope you get a more complete answer.


SCJP
Visit my download page
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Quick and dirty test (only run under IE5.0) but it shows that it works:

Dave
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Oh, and just for the record, never ever call a button, element or anything else 'submit' since document.form.submit(); no longer works...

Dave
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

request.getParameter looks good to me
Aj Manch
Ranch Hand

Joined: May 07, 2001
Posts: 50
Originally posted by Randall Twede:
request.getParameter looks good to me

Randall and David,
Isn't what you mentioned, JSP? I am looking for the client side javascript to distinguish between the Submit and the Cancel buttons so that I could validate some fields if it is a submit button. Unfortunately, the servlet's logic decides which screen to display so I have to "Submit" both of these buttons.
-Ajay
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

See if this code helps you -

HTH,
- Manish
[This message has been edited by Manish Hatwalne (edited October 25, 2001).]
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
David, tell me you jest about document.form.submit()??? If not, where did you get that info?
Thanks,
Joel


Wait a minute, I'm trying to think of something clever to say...<p>Joel
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

yeah request.getParameter is java code but since david posted it i thought maybe js had the same thing. much javascript code is the same as java. sorry im not much of a js expert.
Aj Manch
Ranch Hand

Joined: May 07, 2001
Posts: 50
Manish your technique is exactly what I was looking for. I also tried making the Submit button a "Button" instead of "Submit" and then call the submit method from inside the Javascript if validations looked ok. The problem with this approach is that the name,value parameter pair of the button that is clicked is missing in the request object.
Thanks all for all your help!!
-Aj
 
 
subject: Identifying the submit button
 
Similar Threads
question about object casting
the enter key forces a submit
Submitting a form on pressing Enter key
How to prevent to click multi submit button?
Authorization problem (!!!NOT SOLVED!!!)