문제

I am working on a dropdown change event, but I am not able to set a condition for the change event. For the second dropdown(subsel) I want a list of values for which the value in sel is NOT present. So far all I'm able to do is reflect the value in first select dropdown into the second dropdown.

<script>$(document).ready(function() {
    $("#sel").live('change', function() {
       $("#selsub").val($(this).val());
    });
});</script>

<form method="get">
    <label for="category">Parent Category</label>
    <select name="sel" id="sel">
    <?php 
        include('connection.php');
        $query_parent=$query=mysql_query("SELECT * from stations");
    <?php while($row = mysql_fetch_array($query_parent)): ?>
    <option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>
    <?php endwhile;?>
</select>
<br/><br/>

<label>Sub Category</label>
<div class='detail'>
        <select name="selsub" id="selsub">
    <?php
         $query=mysql_query("SELECT * from stations");
         while($row1 = mysql_fetch_array($query)): ?>
        <option value="<?php echo $row1['name']; ?>"><?php echo $row1['name']; ?></option>
    <?php endwhile; ?>
</select>
</div>

Kindly help me to set a condition where in the second dropdown(selsub) all the values would appear except the value one in first dropdown(sel).

도움이 되었습니까?

해결책

Try to do:

$(document).ready(function() {
    $("#sel").on('change', function() {
        selectedVal = this.value;
        $("#selsub option[value='" + selectedVal +"']").hide();
    });
});
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top