Solved

Calling servlet onchange event

Posted on 2004-08-10
7
6,079 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
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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&para2=value2';">

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article, I will show you HOW TO: Suppress Configuration Issues and Warnings Alert displayed in Summary status for ESXi 6.5 after enabling SSH or ESXi Shell.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now