?
Solved

Calling servlet onchange event

Posted on 2004-08-10
7
Medium Priority
?
6,724 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 200 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
Industry Leaders: 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

765 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