如果我选择第一个方框,则第二个方框将被更改,反之亦然。
echo '<td><select id=hello name=hello onchange=my()>';
while($fet=mysql_fetch_assoc($sql1))
{
echo "<option value=".$fet['username'].">".$fet['username']."</option>";
}
echo '</select></td>';
echo "<td><div id='myDiv'><select id=id name=id onchange=my1()>";
while($fet=mysql_fetch_assoc($sql1))
{
echo "<option value=".$fet['id'].">".$fet['id']."</option>";
}
echo '</select></div></td>';
答案 0 :(得分:1)
Jquery:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
</script>
<script>
$(function(){
$('#name-first').on('change',function(){
var selIndex= $("#name-first option:selected").index();
$("#name-second option").eq(selIndex).prop('selected', true);
});
});
$(function(){
$('#name-second').on('change',function(){
var selIndex= $("#name-second option:selected").index();
$("#name-first option").eq(selIndex).prop('selected', true);
});
});
</script>
//select 1
<select name="cnoption1" id="name-first" onchange=loadXMLDoc()>';
$op="select * from t_category";
$op1=mysql_query($op); while ($row = mysql_fetch_array($op1))
{
echo '<option value='.$row["categoryname"].'>' .$row["categoryname"].' </option>';
}
echo '</select></div></td>';
//select 2
echo '<select name="cioption2" id="name-second" class="InputField">';
$opt="select * from t_category";
$opt1=mysql_query($opt); while ($row1 = mysql_fetch_array($opt1))
{
echo '<option value='.$row1["categoryid"].'> '.$row1["categoryid"].' </option>'; }
echo '</select></p></div></td>';