2015-02-28 10:40
浏览 33


Hie,I had asked this question already but I have make it briefly now please share some logic. 1st dropdown List-enter image description here Contain Class-1, class-2, class-3..etc. 2nd dropdown List-enter image description here Depends on class.If we chose class-1 and class-2 then respective Student Id will show on 2nd dropdown list. I want selected Classes in respective variables and selected turbines in respective variable. Then I will get this selected variables and use in another page.

I want multiple selection in each dropdown list. suppose I have select one Class-1 then, On the classId second dropdown list will fill with respective studentID,again I am select another class-2 then again Add respective studentID list in 2nd dropdown list.

In my databse script ClassId and StudentId this attribute present in same table only (not diffrent tables).

Table view somewhat like this->

 ClassID    StudentID   StudentNm 
      1        101         abc 
      1        102         xyz 
      1        103         jkl 
      2        201         uio
      2        202         tyu 
      3        302         qwe 
      3        305         zxc
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanputian5341
    duanputian5341 2015-02-28 11:30

    Try this

        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <select multiple="multiple" name="classId" class="select-box">
        <option value="1">Option 1</option>
        <option value="2">Option 2</option>
        <option value="3">Option 3</option>
        <option value="4">Option 4</option>
        <option value="5">Option 5</option>
     <script src=""></script>
            var classId = $(this).val();
                url : 'getSub.php',
                type: 'POST',
                dataType : 'JSON',
                data : {
                    'classId' : classId,
                success : function(data){

    When you print selectedValues values will be printed in array format. in getSub.php you can get values and send it as json


    $classIds = implode(',', $_POST['classId']);
    $stmet = "SELECT StudentID from TBL where ClassID IN ('$classIds')";
    $query = mysql_query($stmet);
    $result = mysql_fetch_array($query);
    echo json_encode($result);
    点赞 评论
  • doucong8553
    doucong8553 2015-02-28 11:43

    try this sample

    your table shoule be like this

       CREATE TABLE 'data'
       'id' int primary key auto_increment,
        'data' varchar(50),
         'weight' int(2),
      CREATE TABLE `data_parent` 
      `pid` int(11) primary key auto_increment,
      `did` int(11) unique,
      `parent` int(11),
      Foreign key(did) references data(id)

    <script type="text/javascript" src="
    <script type="text/javascript">
    var id=$(this).val();
    var dataString = 'id='+ id;
    type: "POST",
    url: "ajax_city.php",
    data: dataString,
    cache: false,
    success: function(html)
    Country :
    <select name="country" class="country">
    <option selected="selected">--Select Country--</option>
    $sql=mysql_query("select id,data from data where weight='1'");
    echo '<option value="'.$id.'">'.$data.'</option>';
    } ?>
    </select> <br/><br/>
    City :
    <select name="city" class="city">
    <option selected="selected">--Select City--</option>

    点赞 评论