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.
<td><select name="CHECK" onchange="SERVLET">
      <option value="1">1</option>
      <option value="2">2</option>

Anyone has any idea how to call servlet within the page without submitting the form.
LVL 11
Who is Participating?
sompol_kiatkamolchaiConnect With a Mentor Commented:
You can not call servlet directly from javascript.
you have to create hidden from and call submit. here is an example

<form name="form1" action="SERVLET" method="POST">
<select name="CHECK" onchange="document.form1.submit();">
     <option value="1">1</option>
     <option value="2">2</option>
>>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
you can call a servlet using a form with its action and method(POST or GET)
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

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

i think then it should work


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://';">

With parameters
<select name="CHECK" onchange="location.href = 'hrrp://¶2=value2';">

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.