This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of React Cookbook: Recipes for Mastering the React Framework and have David Griffiths & Dawn Griffiths on-line!
See this thread for details.
Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 :(
 
If you look closely at this tiny ad, you will see five bicycles and a naked woman:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic