Solved

Calling servlet onchange event

Posted on 2004-08-10
7
6,477 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:raj3060
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 11

Accepted Solution

by:
sompol_kiatkamolchai earned 50 total points
ID: 11768903
You can not call servlet directly from javascript.
you have to create hidden from and call submit. here is an example

<html>
<form name="form1" action="SERVLET" method="POST">
<select name="CHECK" onchange="document.form1.submit();">
     <option value="1">1</option>
     <option value="2">2</option>
</select>
</form>
</form>
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11768907
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
0
 
LVL 3

Expert Comment

by:ss_p
ID: 11771710
you can call a servlet using a form with its action and method(POST or GET)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Author Comment

by:raj3060
ID: 11772862
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
0
 
LVL 3

Expert Comment

by:ss_p
ID: 11773661
add the

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

i think then it should work

prasannaa
0
 
LVL 11

Expert Comment

by:sompol_kiatkamolchai
ID: 11790032
raj3060,

It's not a hidden from. I type wrong. please see in the second comment :)
0
 
LVL 1

Expert Comment

by:umangjoshi
ID: 11799268
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';">

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
Not everyone has adapted to a rapid advancement in technology; there are people who are reluctant or afraid to delve into this brave new world of IT. If you have a friend or a family member who suffers from the so-called technophobia, here is how yo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question