Wrox Programmer Forums
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 7th, 2006, 07:05 AM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Struts

There are 2 combos. one combo contains Country, and another combo contains State of that country. My question is how can i change the state, after selecting the country, without reloading the JSP page.
How we can handle this in Action/EJB with JSP page.
 
Old April 9th, 2006, 05:18 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

HI ms_shilpa!!
onchange of counrty combobox ,add corresponding state into StateCombobox.

now it's upto you and your requirement,either you can use AJAX to load StateCombobox values or you can use hidden field for this.

e.g.
step1>Countrycombo ->country1,country2,country3 etc.

step2>put all the state values/names for all the countries in a singlehidden field
like
<input type=hidden name="countrystatevalue"
 value="<option value='1'>Country1state1</option><option value='2'>Country1state2</option><option value='3'>Country1state3</option>+++<option value='1'>Country2state1</option><option value='2'>Country2state2</option><option value='3'>Country2state3</option>+++<option value='1'>Country3state1</option><option value='2'>Country3state2</option><option value='3'>Country3state3</option>">

step3>onchange of country you can get the value_state of that country .
e.g user is selecting country1, it has option value="1_2"
where 1 stand for country code,
  2 stand which statevalue should be populated from hidden countrystatevalue field.

now split countrystatevalue value based on "+++" delimeter (you can choose ur own delimeter)
and
then document.getElementById("StateComboName").innerHTM L=countrystatevalue.split('+++')[i]
where i is the second value of 1_2 .i e 2

hope follwing code will help you
******************test.html**************
<script>

function setState()
{

totaloption=document.getElementById("state").lengt h;
for(i=totaloption-1;i>=0;i--)
{
 document.getElementById("state").options[i]=null
 }

if(document.getElementById("country").selectedInde x<1)
 return

optionvalue=(document.getElementById("countrystate value").value).split("+++")[((document.getElementById("country").value).split( "_"))[1]-1]


tmpoptions=optionvalue.split("//")
for(i=0;i<tmpoptions.length;i++)
{
optionvaluestr=tmpoptions[i].split("--")[0]

optionTxt=optionvaluestr.split("--")[0]
optionValue=optionvaluestr.split("--")[1]
newoption= new Option(optionTxt,optionValue);
document.getElementById("state").options[document.getElementById("state").length]=newoption;
}
}
</script>
<html>
<select name="country" id="country" onchange="setState()">
<option value="">Select Country</option>
<option value="10_1">Country1</option>
<option value="11_2">Country2</option>
<option value="12_3">Country3</option>
<option value="13_4">Country4</option>
<option value="14_5">Country5</option>
</select> <br>
<select id="state" name="state">
</select>
<br>
<input type=hidden id=countrystatevalue
 value="Country1state1--1//Country1state2--2//Country1state3--3//Country1state4--4+++Country2state1--1//Country2state2--2//Country2state3--3//Country2state4--4+++Country3state1--1//Country3state2--2//Country3state3--3//Country3state4--4+++Country4state1--1//Country4state2--2//Country4state3--3//Country4state4--4+++Country5state1--1//Country5tate2--2//Country5state3--3//Country5state4--4">





Cheers :)

vinod





Similar Threads
Thread Thread Starter Forum Replies Last Post
struts actions package: "struts", other packages? ojasrege Struts 1 July 21st, 2007 06:02 AM
About Struts tulmohan BOOK: Professional Jakarta Struts 0 December 13th, 2006 03:00 AM
about struts kishore.dyn Struts 4 August 8th, 2006 01:28 AM
How to get upgraded from Struts 1.1 to struts 1.2. [email protected] Struts 0 January 3rd, 2006 04:29 AM
Need help with struts pkmleo J2EE 1 February 27th, 2005 06:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.