By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,212 Members | 1,277 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,212 IT Pros & Developers. It's quick & easy.

What submit button was pressed? Same form, another page (JSP)!

P: 7
Later edit:

Too complex:

The only thing I should know is:
The submit button's NAME (and value) will only be sent if that particular button was used to submit the form, so you should be able to check that in the server side script.

Rest is history:

Hello to everybody. I'm new in everything and I need your help.

How can I checked what submit button was pressed?

I have something like this:

input - I collect info

submit button1 GOTO to page1.jsp for processing the info using formula 1
submit button2 GOTO to page1.jsp for processing the info using formula 2

I tried something like this:

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2.     <HEAD>
  3.         <TITLE>Using Buttons</TITLE>
  4.     </HEAD>
  6.     <BODY>
  7.         <% 
  9.         String s = request.getParameter("buttonName") ***********************************************************
  11.         %>
  13.         <FORM NAME="form1" METHOD="POST">
  14.             <INPUT TYPE="HIDDEN" NAME="buttonName">
  15.             <INPUT TYPE="BUTTON" VALUE="Button 1" ONCLICK="button1()">
  16.             <INPUT TYPE="BUTTON" VALUE="Button 2" ONCLICK="button2()">
  17.         </FORM>
  19.         <SCRIPT LANGUAGE="JavaScript">
  20.             <!--
  21.             function button1()
  22.             {
  23.                 document.form1.buttonName.value = "button 1"
  24.                 form1.submit()
  25.             }    
  26.             function button2()
  27.             {
  28.                 document.form1.buttonName.value = "button 2"
  29.                 form1.submit()
  30.             }    
  31.             // --> 
  32.         </SCRIPT>
  33.     </BODY>
  34. </HTML>
This is example witch I found on the internet, but in my case I need the know what button was pressed in ANOTHER page(not the same), so I put the line with the stars in the page1.jsp (where I process the info), but the value of the string is null.
So.. Can you help me?:)
Aug 10 '09 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 8,639
wouldn’t it make more sense if you process formula1/2 within the server script?

back to your question, the basic difference between the buttons are the buttons itself (sounds complicated?).
you only need one attribute in each of the buttons, that is different between those (could be anything, but id and name would be the obvious ones)

definitely a server side issue. there’s no communication between two pages without the server.
Aug 10 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.