• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in passing drop down value to a servlet using href link

 
M Jiva
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Description: I want to pass a integer parameter and the selected value from a drop down box to a servlet using a href link. The visible jsp code is written in a java servlet. When i fetch the values of the passed parameters in the next servlet("ToggleStatus" in my case) i get the correct value for the integer parameter ("emp_no") but for the drop down value parameter "rg" it shows "form.this.reason[selectedindex].value" instead of the actual value.


This code is written in a java servlet.

int emp_no=20;

String reason1="";
reason1="good";
reason2="bad";
out1.println("<form name='try' id='try'><table>");

out1.println("<tr><td>"+emp_no+"</td><td><select name='reason' id='reason'><option value='0'>Select Action</option><option value='1'>"+ reason1 +"</option><option value='2'>"+ reason2 +"</option></td><td><a href='ToggleStatus?emp_no="+emp_no+"&rg=form.this.reason[selectedindex].value'>Change</a></td></tr>");

out1.println("</form></table>");

Result:
String emp_no=request.getParameter("emp_no");
String rg=request.getParameter("rg");
system.out.println("emp_no = "+emp_no+" :: rg = "+rg);

Output:

emp_no = 20 :: rg = form.this.reason[selectedindex].value

Where the expected result is rg = 1 (if i select the first option)
I would appreciate any help in this regard.
 
Sean Clark
Rancher
Posts: 377
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

Is there any reason that you are not using an submit button and are using a link? The reason you are getting that is that you are trying to use javascript, but you haven't got the syntax right at all.

The simplest way is just to use a submit button (that's what it is for after all). Experiment with javascript after you get a basic one working.

put somewhere in your form:

and try that.

Sean
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. You can edit your post by using the button.

And there's a reason HTML and Java code were separated into Java classes and JSPs :(
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!