dongwang6837 2016-08-29 06:20
浏览 57

选择第一个下拉值时,第二个下拉列表不会填充

I have two table ,

  1. state where StCode, StateName

2.district where DistCode, StCode, DistrictName

My code for first Drop down

<td><label for="studentstate"></label>
      <select name="studentstate" id="studentstate">
        <?php
                $con=mysql_connect("localhost","root","");
                if(!$con)
                    {   
                    die('could not connect:'.mysql_error());
                    }

                    mysql_select_db("db_loan",$con);

                    $sqlstr="select StCode,StateName from state";

                    $result=mysql_query($sqlstr);

                    while($row=mysql_fetch_array($result))
                    {
                    echo '<option value="'.$row['StCode'].'">'.$row['StateName'].'</option>';

                    }
                    echo $sccode=$row['StCode'];

            ?>
      </select></td>

Now i have try following for second dropdownlist where i want to show district name

    <div id="result">
        <input type="button" value="Reload"></input>
          <select name="studentdist" id="studentdist">
          <?php 

          $con=mysql_connect("localhost","root","");
                    if(!$con)
                        {   
                        die('could not connect:'.mysql_error());
                        }

                        mysql_select_db("db_loan",$con);

                        $sqlstr="select DistCode,DistrictName from district where StCode='$sccode'";

                        $result=mysql_query($sqlstr);

                        while($row=mysql_fetch_array($result))
                        {
                        echo '<option value="'.$row['DistCode'].'">'.$row['DistrictName'].'</option>';

                        }
                    //  echo $sccode=$row['DistCode']; 
          ?> 
          </select></td>
</div>

Now if i what i should do for reload my div when select first value from drop down list

Please if you know please tell me how to do it without using ajex or jquery

After read suggestion from mirza i have updated my code as follow but still there it is not working

</head>
    <script type="text/javascript">


    $("#studentstate").change(function() 
    {
      $("#studentdist").load("pag1.php?choice=" + $("#studentstate").val());
    });

    </script>


    <body>
  • 写回答

1条回答 默认 最新

  • duancanjiu3754 2016-08-29 06:31
    关注

    you need some JQuery Basic to do this task

    <script type="text/javascript">
    $("#first-choice").change(function() {
      $("#second-choice").load("getter.php?choice=" + $("#first-choice").val());
    });
    </script>
    

    getter.php replace with your php page name and it will work

    评论

报告相同问题?