我有一个问题,我ihnk我的函数可以处理1选择,但在我的选项里面我使用循环但我不知道为什么它不起作用因为我使用循环所以它应该工作,它只能一次工作。需要一些帮助
这是我的代码:
<script>
function getImage1(str) {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("result1").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getImage.php?no="+str,true);
xmlhttp.send();
}
</script>
===========这是我在PHP中的代码
<select onchange="getImage1(this.value)" name="<?php echo $rowasa['pos_name'] ?>" style="height: 47px;">
<option value='0' >Pls. Select <?php echo $rowasa['pos_name'] ?></option>
<?php
include('connection/connect.php');
$dsds=$rowasa['posid'];
$YearNow=Date('Y');
$results = $db->prepare("SELECT * FROM candidates,student,school_year,partylist where student.idno = candidates.idno AND school_year.syearid = candidates.syearid AND posid =:a AND candidates.partyid = partylist.partyid AND school_year.from_year like $YearNow ");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
?><!---$rows['candid'] . "," .-->
<option style="padding: 35px 50px 35px 80px; background:url('admin/candidates/images/<?php echo $rows['image']; ?>') no-repeat scroll 5px 7px / 70px auto rgba(0, 0, 0, 0);"
value="<?php echo $rows['candid'] . "-" ." ". $rows['lastname'] .",". " ". $rows['firstname'] ?>"> <?php echo $rows['lastname'] ?>,
<?php echo $rows['firstname'] ?>
- <?php
echo $rows['party_name']?></option>
<?php
}
?>
</select>
// here's the id