Hi Arun,
I too struggled for this and I have somehow managed to do it with some difficulty.
So use it and save ur time.I am sending the code.
In my case : The country and state are stored in SQL.
mgr.getListSorted("Country_Key")will fetch
Country Key : IN
Country Value : India
mgr.getSub_List("State") will fetch the following from the table
State Key :IN-TN
State Value :Tamilnadu
<tr>
<td width="30%"><b>Country key *</b></td>
<td width="70%">
<!-------------------------------Country-State Code Starts Here -------------------------->
<%
//Get the Country List
TreeMap tm_Country = mgr.getListSorted("Country_Key");
Collection col_Country = tm_Country.values();
Set set_Country = tm_Country.keySet();
Iterator it_Country_Elements= col_Country.iterator();
Iterator it_Country_Keys= set_Country.iterator();
//Get the State List
Hashtable ht_State = mgr.getSub_List("State");
Enumeration enum_State_Elements = ht_State.elements();
Enumeration enum_State_Keys = ht_State.keys();
String key="";
String val="";
String statekey="";
String statevalue="";
String countrykey="";
%>
<select name="cmb_Country" onChange="val()">
<option value = "-1" selected>--Select a Country--</option>
<%
while(it_Country_Elements.hasNext() && it_Country_Keys.hasNext())
{
key = (String)it_Country_Keys.next();
val = (String)it_Country_Elements.next();
%>
<option value = "<%out.println(val);%>" ><%out.println(key);%></option>
<%
}
%>
</select>
<script language="javascript">
var Country_Code = new Array();
<%
while(it_Country_Keys.hasNext())
{
int ctr=0;
countrykey = (String)it_Country_Keys.next();
%>
Country_Code[<%=ctr%>]="<%=countrykey%>";
<%
ctr++;
}
%>
var State_Code = new Array();
var State_Desc = new Array();
var State_Code_Actual = new Array();
<%
int i=0;
String str_State_Code = null;
while(enum_State_Elements.hasMoreElements() && enum_State_Keys.hasMoreElements())
{
statekey = (String)enum_State_Keys.nextElement();
statevalue = (String)enum_State_Elements.nextElement();
StringTokenizer st = new StringTokenizer(statekey,"-");
while (st.hasMoreTokens())
{
str_State_Code = st.nextToken();
}
str_State_Code= str_State_Code.trim();
System.out.println(str_State_Code);
%>
State_Code[<%=i%>]="<%=statekey%>";
State_Desc[<%=i%>]="<%=statevalue%>";
State_Code_Actual[<%=i%>]="<%=str_State_Code%>";
<%
i++;
}
%>
</script>
<script language="JavaScript">
function val()
{
while(document.frm_Address_Create.cmb_State.options.length)
{
document.frm_Address_Create.cmb_State.options[0] = null;
}
document.frm_Address_Create.cmb_State.options[0] = new Option("Select a State","-1")
var country_value = document.frm_Address_Create.cmb_Country.value;
country_value = country_value.substring(0,2);
var k=1;
for(var l=0; l < State_Code.length;l++)
{
State_Code[l] = State_Code[l].substring(0,2);
if(country_value == State_Code[l])
{
document.frm_Address_Create.cmb_State.options[k] = new Option(State_Desc[l],State_Code_Actual[l]);
k++;
}
}
}
</script>
<!-------------------------------Country-State Code Ends Here -------------------------->
</td>
</tr>
<tr>
<td width="30%"><b>State *</b></td>
<td width="70%">
<select name="cmb_State">
<option value = "-1" selected>Select a State</option>
</select>
</td>
</tr>
Regards,
Hari
"Happiness is Perfect only when Shared"