File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Identifying the submit button

 
Aj Manch
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quick and dirty test (only run under IE5.0) but it shows that it works:

Dave
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
request.getParameter looks good to me
 
Aj Manch
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2591
Android Firefox Browser Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this code helps you -

HTH,
- Manish
[This message has been edited by Manish Hatwalne (edited October 25, 2001).]
 
Joel Cochran
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David, tell me you jest about document.form.submit()??? If not, where did you get that info?
Thanks,
Joel
 
Randall Twede
Ranch Hand
Posts: 4353
2
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic