Link to home
Start Free TrialLog in
Avatar of raj3060
raj3060Flag for United States of America

asked on

Calling servlet onchange event

Hi experts,
I am creating a form in JSP, that has different dropdown boxes. For few boxes when we select certain option new input fields appear on screen for example- If from a drop down box that has options:Name, Age,Address, etc., say I select address option then 5 new input fields should appear on screen, i.e. add1, add2, city, state, zip. Now if I select the Name only two fields should appear i.e. First Name, and Last Name. and this time all adress fields should disappear.
Logic is simple, when we select option call servlet and set some value and reload the JSP with the new fields depending on the set value. Now I have done it, but the problem is when I change option and try to call servlet, it does not work.
<tr><td>Option</td>
<td><select name="CHECK" onchange="SERVLET">
      <option value="1">1</option>
      <option value="2">2</option>
</select></td></tr>

Anyone has any idea how to call servlet within the page without submitting the form.
Thanks
ASKER CERTIFIED SOLUTION
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry.
>>you have to create hidden from and call submit. here is an example
you have to create form and call submit. here is an example
Avatar of ss_p
ss_p

you can call a servlet using a form with its action and method(POST or GET)
Avatar of raj3060

ASKER

Hi Sompol,
It works, but I wanna know how to create a hidden form, right now I used the main form and it works.
--Raj
add the

style="display:'none';" attribute in form field

i think then it should work

prasannaa
raj3060,

It's not a hidden from. I type wrong. please see in the second comment :)
sompol_kiatkamolchai  is right, you can write the code as follows

<select name="CHECK" onchange="location.href = 'hrrp://www.myweb.com/servlets/myservlet';">

With parameters
<select name="CHECK" onchange="location.href = 'hrrp://www.myweb.com/servlets/myservlet?para1=value1¶2=value2';">