Help on onchange event for refreshing the page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ruds

    Help on onchange event for refreshing the page

    Hello,
    I have a JSP page in which HTML form elements are present.
    I have a drop down list named Country, when a user selects his country
    I want another drop down list to populate based on the first list the
    names of coresponding states in that country.
    For this I want to retrive values from database onchange event of the
    first drop down list.
    My code is:
    <HTML>
    <HEAD>
    <SCRIPT language=javasc ript>
    function Select_Index(fo rm)
    {
    var ctry = document.f1.Cnt ry.options
    [document.f1.Cnt ry.selectedInde x].value
    var HREF="./GetInfo.jsp?Ctr y='"+ctry+"'"
    window.open(HRE F, "_self")
    }
    </SCRIPT>
    </HEAD>
    <BODY>
    <TABLE>
    <TR>
    <TD>Country</TD>
    <TD><select name="Cntry" size="1" onchange="Selec t_Index(this.FO RM)">
    <%
    rs=stmt.execute Query("select * from Country");
    while(rs.next() ){
    String cnt=rs.getStrin g(2);
    %>
    <OPTION VALUE="<%=cnt%> "><%=cnt%></OPTION>
    <%
    }
    %>
    </select> </TD </TR>
    <TR>
    <TD>State</TD><TD><select name="state" size="1">
    <OPTION VALUE="" selected></OPTION>
    <% rs=stmt.execute Query("select ID from Country where
    Country="+Cntry );
    while(rs.next() ) {int cid=rs.getInt(1 ); }
    String states1[]=new String[50];
    int j=0;
    rs=stmt.execute Query("select State from States where
    CID="+cid);
    while(rs.next() ) {
    states1[j]=rs.getString(1 );
    j++; }
    for(int i=0;i<states1.l ength;i++)
    { %>
    <OPTION VALUE="<%=state s1[i]%>"><%=states 1[i]%></OPTION>
    <% } %>
    </select </TD</TR>
    </TABLE>
    </BODY>
    </HTML>

    As given in the above code onchange event of first drop down my
    Select_Index function is called which reopens the page with attribute
    ctry as parameter which is used in turn to populate my second drop
    down list.
    But this is not happening, please tell me how to achieve the same.
  • David Mark

    #2
    Re: Help on onchange event for refreshing the page

    On Nov 19, 2:55 am, ruds <rudra...@gmail .comwrote:
    Hello,
    I  have a JSP page in which HTML form elements are present.
    I have a drop down list named Country, when a user selects his country
    I want another drop down list to populate based on the first list the
    names of coresponding states in that country.
    For this I want to retrive values from database onchange event of the
    first drop down list.
    From the what of the what? You need to ask in a JSP group.
    My code is:
    <HTML>
    <HEAD>
    <SCRIPT language=javasc ript>
    Lose the language attribute. Use type="text/javascript".

    function Select_Index(fo rm)
    {
      var ctry = document.f1.Cnt ry.options
    [document.f1.Cnt ry.selectedInde x].value
    Don't assume that a form can be referenced as a property of the
    document object (use the forms property.) Similar problem with
    elements.
      var HREF="./GetInfo.jsp?Ctr y='"+ctry+"'"
    Why CAPS? And why the funny URI?
      window.open(HRE F, "_self")}
    Is this running in a frame?
    >
    </SCRIPT>
    </HEAD>
    <BODY>
    <TABLE>
    <TR>
    <TD>Country</TD>
    <TD><select  name="Cntry" size="1" onchange="Selec t_Index(this.FO RM)">
    <%
      rs=stmt.execute Query("select * from Country");
      while(rs.next() ){
        String cnt=rs.getStrin g(2);
    %>
       <OPTION VALUE="<%=cnt%> "><%=cnt%></OPTION>
    <%
      }
    %>
    Don't post server side code mixed with client side code (even if they
    are both Javascript.)

    [snip]
    >
    As given in the above code onchange event of first drop down my
    Select_Index function is called which reopens the page with attribute
    ctry as parameter which is used in turn to populate my second drop
    down list.
    But this is not happening, please tell me how to achieve the same.
    Start by expounding on "not happening."

    Comment

    Working...