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
Solved

Calling servlet onchange event

Posted on 2004-08-10
7
6,335 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
attribute vs parameter and setter vs add method 17 89
iterator example remove 8 75
sortaSum challenge java 17 173
How to Post an If Statement in JSP 3 60
Is your phone running out of space to hold pictures?  This article will show you quick tips on how to solve this problem.
The advancement in technology has been a great source of betterment and empowerment for the human race, Nevertheless, this is not to say that technology doesn’t have any problems. We are bombarded with constant distractions, whether as an overload o…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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