根据第一个字段中的选择更改字段数

时间:2016-11-24 10:48:28

标签: javascript php jquery ajax

我想根据第一个字段中的选择更改字段数。

我希望第二个字段是基于第一个字段中的选择的选择或文本输入。

我根据选择获得了另外一个字段,但是如何获得多个字段?

我的HTML代码:

<form method="post" action="" >
  <div class="row">
    <div class="col-sm-4">
      <div class="form-group">
        <label>Search By </label>
        <select class="form-control margin-bottom-20"  name="search1" id="search1">
          <option value="">Select</option>
          <option value="name">Name</option>
          <option value="mobile">Mobile</option>
          <option value="program_name">Program</option>
          <option value="program_schedule">Program & Schedule</option>
          <option value="program_schedule_shift">Program, Schedule & Shift</option>
        </select>
      </div>
    </div>
    <div class="col-sm-4">
      <div class="form-group">
        <label>Detail </label>
        <select class="form-control margin-bottom-20"  name="date" id="date">
        <?php include 'get_sch.php'; ?>
        </select>
      </div>
    </div>
  </div>
  <hr>
  <div class="col-sm-4">
    <div class="form-group"> 
      <button type="submit" class="btn btn-primary" name="submit" id="submit">Search</button>
    </div>
  </div>
</form>

我的jQuery代码是:

  $(document).ready(function() {

      $("#submit").click(function() {
          var search1 = $('#search1').val();
          var detail = $('#detail').val();
          var dataString = 'search1=' + search1 + '&detail=' + detail;

          $.ajax({
              type: "POST",
              url: "get_enquiry_details.php",
              data: dataString,
              cache: false,
              success: function(result) {
                  $("#date").html(result);
              }

          });
      });
  });

PHP代码:

$group = $_POST['search1'];
$gender = $_POST['detail'];

$selectquery = "SELECT * FROM `enquiry` WHERE `$group` = '$gender'" ;

$group_result = mysql_query($selectquery, $conn);

while ($container_id_record = mysql_fetch_assoc($group_result)) {
    $i++;
    echo "<tr class='gradeA odd' role='row'><td class='sorting_1'>" .
         $container_id_record['enquiry_date'] . "</td><td>" .
         $container_id_record['name'] . "</td><td>" .
         $container_id_record['mobile'] . "</td><td>" .
         $container_id_record['program_name'] . "</td><td>" .
         $container_id_record['schedule'] . "</td><td>" .
         $container_id_record['shift'] . "</td><td>" .
         $container_id_record['remark'] . "</td>";
}

0 个答案:

没有答案