Hi,
I am developing javascript applications and I have one doubt.I have two dropdown list box,one for state and another for city.If we click one state, you will get related cities for that state.It working well and I have one button for submit.
once we click submit button we will go to cities page.It is working fine.In that city page we click back button,we will get previous page I is also working well but selected state is there but city box shows select.It didn't show any cities.once we refresh that page it shows all the cities.
Code:<html> <head> <SCRIPT LANGUAGE="JavaScript"> function checkForm() { var city1 = document.form1.select2.value; if(city1=="") alert(" Please select any city"); if(city1=="1") window.location="http://www.one.in"; if(city1=="2") window.location="http://www.two.in"; if(city1=="3") window.location="http://www.three.in"; if(city1=="4") window.location="http://www.four.in"; if(city1=="5") window.location="http://www.five.in"; if(city1=="6") window.location="http://www.six.in"; if(city1=="7") window.location="http://www.seven.in"; if(city1=="9") window.location="http://www.eight.in"; if(city1=="10") window.location="http://www.nine.in"; if(city1=="11") window.location="http://www.ten.in"; if(city1=="13") window.location="http://www.one1.in"; if(city1=="14") window.location="http://www.one2.in"; if(city1=="15") window.location="http://www.one3.in"; if(city1=="16") window.location="http://www.one.in"; } </script> </head> <title>hello</title> <body> <form name="form1"> <DIV align=left> <SELECT name=select onChange="redirect(this.options.selectedIndex)"> <OPTION id="se">Select</OPTION> <option>Andhra Pradesh</option> <option>Gujarat</option> <option>Karnataka</option> <option>Maharashtra</option> </SELECT> </DIV></TD></TR> <tr align="left" valign="top"> <td height="0"> <div align="center"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif"> <strong> City : </strong></font></div></td> <td> <select name="select2"> <option>Select</option> </select> </td> </tr> <script> var groups=document.form1.select.options.length var group=new Array(groups) for (i=0; i<groups; i++) group[i]=new Array() group[0][0]=new Option("Select City") group[1][0]=new Option("Select City") group[1][1]=new Option("Hyderabad","5") group[2][0]=new Option("Select City") group[2][1]=new Option("Ahmedabad","7") group[2][2]=new Option("Surat","28") group[3][0]=new Option("Select City") group[3][1]=new Option("Bangalore","2") group[4][0]=new Option("Select City") group[4][1]=new Option("Mumbai","3") group[4][2]=new Option("Pune","6") var temp=document.form1.select2 function redirect(x){ for (m=temp.options.length-1;m>0;m--) temp.options[m]=null for (i=0;i<group[x].length;i++){ temp.options[i]=new Option(group[x][i].text,group[x][i].value) } temp.options[0].selected=true } </script> </form> <tr align="left" valign="bottom"> <td height="40" colspan="2"> <table width="68" height="22" border="0" align="center" cellpadding="0" cellspacing="0"> <tbody> <tr> <td> <a onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image16','','images/submit_rollover_pic.jpg',1)" " onClick="checkForm()" ><img src="images/submit_pic.jpg" name="Image16" width="68" height="22" border="0"> </a> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </td> </tr> </tbody> </table> </body> </html>



Bookmarks