html - How can I pass a parameter via submit button? -


In my code for a mini online book store, I have been duplicated with different values ​​5 times for the 'name' parameter. The row is

  & lt; Input name = "JSP-2" type = "submit" value = "buy" & gt;  

On clicking the Buy button, this application redirects the buy.jsp file where it receives the value of the name and displays the related details of the book.

In my Buy.jsp, I have included

  & lt;% string bname = request.getParameter ("name"); Out.print (bname); & Gt%;  

But the name bname is not assigned and it shows the value as zero. How do I pass a parameter from the submit type input? help please.

You have to pass the parameter in the request. Since you are creating a form and submitting the form, you can say a hidden field as the name, "Type submit", and whenever you click on the button using Javascript It will be available in the next request.

Anywhere inside the form: & lt; Input type = "hidden" name = "type deposit" & gt;

< formName
& lt; Input name = "JSP-2" type = "submit" onclick = "setType ('buy')" & gt;

/ Em> is the name of your form

  & lt; Script & gt; The function set type (type) {// FormName is the name of your form, submitType is the name of the submit button. Document.forms ["formName"]. Element ["submitType"]. Value = type; // Alternatively, you can access the button by your ID document .getElementById ("submitId") value = type; } & Lt; / Script & gt;  

Comments