We used on onClick="" javascript in each button or image for submitting the form.
I take it the value you set is based on the counter in your code? So the variable 'j' in your counter is the ID value you would set? I also take it that your message[] array is indeed populated when the JSP page is requested, so that message[0], message[1] and so on has values in it up to message.length? At any rate, I would change what you have to something like: for (int cntr = 0; cntr < message.length; cntr++) { %> <input type="button" name="<%= message[cntr] %>" value="<%= message[cntr] %>" style="width:200px" onClick="this.form.action='/loginwebapp/servlet1?value=<%= SysID[cntr] %>&msg=<%= message[cntr] %>&kubun=<%= kubun[cntr] %>'"> <% } %> You don't need the Javascript code to submit the form. The onClick above is what we use, and it simply assigns the Action of the form, but doesn't stop it from submitting. If you want an additional trick, you may want to sometimes "validate" forms, or make sure a user wants to take an action before sumbitting a form, you would add the onSubmit="" to the <form .. > tag at the top. This would allow you to run some javascript that can validate fields for example. If something is wrong, you can popup a java box. If you return false, the form is blocked from being submitted. If true is returned, it submits. Hope this helps. > -----Original Message----- > From: Edward [mailto:[EMAIL PROTECTED]] > Sent: Thursday, June 13, 2002 8:01 PM > To: [EMAIL PROTECTED] > Subject: How to set value in JSP and send it to Servlet? > Importance: High > > > I have serveral buttons.When click one of them,I want to set > different value according the button name and send it to > Servlet,for example when click the first button,I want to set > value "001" and "Open",when click the second button,I want to > set value "002" and "Private",and so on. Then transfer it to > Servlet.I want to know how to realize it? My Jsp file like follows: > > <html> > <title>User Menu</title> > <body> > <form name=myform method="get" action = "/loginwebapp/servlet1"> > <% > String message[]; > String syskubun[]; > message=(String[])request.getAttribute("jsp"); > syskubun=(String[])request.getAttribute("SysKubun"); > String SysID[]=new String[message.length]; > String Kubun[]=new String[message.length]; > for(int j=0;j<message.length;j++) > { > ... > %> > <input type="button" name=<%=message[j]%> > value="<%=message[j]%>" > style="width:200px" > onclick="javascript:goToServlet(j)"> > <% > } > </form> > <script language="javascript"> > function goToServlet(int i) > { > //Here I want to set value,such as when i=0,I want to > set the value of SysID[0] and Kubun[0] > //When i=1,I want to set value of SysID[1] and > Kubun[1],how to realize it? > document.myform.submit(); > } > </script> > </body> > </html> > > Thanks very much!!! > Regard, > Edward > > ============================================================== > ============= > To unsubscribe: mailto [EMAIL PROTECTED] with body: > "signoff JSP-INTEREST". > For digest: mailto [EMAIL PROTECTED] with body: "set > JSP-INTEREST DIGEST". > Some relevant FAQs on JSP/Servlets can be found at: > > http://archives.java.sun.com/jsp-interest.html > http://java.sun.com/products/jsp/faq.html > http://www.esperanto.org.nz/jsp/jspfaq.jsp > http://www.jguru.com/faq/index.jsp > http://www.jspinsider.com > ==========================================================================To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant FAQs on JSP/Servlets can be found at: http://archives.java.sun.com/jsp-interest.html http://java.sun.com/products/jsp/faq.html http://www.esperanto.org.nz/jsp/jspfaq.jsp http://www.jguru.com/faq/index.jsp http://www.jspinsider.com