<?php
$sql = "select * from letter where societyn='" . $_SESSION['socityname'] ."' ";
$result = mysql_query($sql);
$i=1;
while($row=mysql_fetch_array($result)){
?>
<?php
$id = $row['id'];
$dater = $row['date'];
$flatnonam = $row['flatno_name'];
$addr = $row['adress'];
$subject = $row['subject'];
$body = $row['body'];
$soci = $row['societyn'];
$refnum = $row['refno'];
$letterh = $row['letterh'];
// split "dd-mm-yyyy" into an array of three elements
$ddate = explode("-", $dater);
// retrieve the values
$month = $ddate[1]; // mm
$day = $ddate[2]; // dd
$year = $ddate[0]; // yyyy
{
?>
<tr>
<td><?php echo $day.'/'.$month.'/'.$year; ?></td>
<td><?php echo $flatnonam; ?></td>
<td><?php echo $letterh; ?></td>
<td><?php echo $addr; ?></td>
<td><?php echo $subject; ?></td>
<td><?php echo $soci; ?></td>
<td><?php echo '#'.$refnum; ?></td>
<td>
<select name="menu1" id="menu1">
<option value="" selected>Pick a Website</option>
<option value="letter/letter_print.php?id=<?php echo $row['id']; ?>">Without Letter Head</option>
<option value="letter/letter_print_nohead.php?id=<?php echo $row['id']; ?>">Letter Head</option>
</select>
</td></tr>
<?php }?>
<?php
echo "<br>";
$i++;
}
?>
<!--This is java script-->
<script type="text/javascript">
var urlmenu = document.getElementById( 'menu1' );
urlmenu.onchange = function() {
window.open( this.options[ this.selectedIndex ].value, '_blank','width=595,height=842,directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
};
</script>
这是我的代码。只有第一个选项,其他工作不正常。 请帮助我遇到麻烦。从2天。或给出另一种解决方案 在一个id中如何使用所有选项。我从2天开始尝试不工作。
答案 0 :(得分:1)
如上所述,将id
更改为class
,因为您有多个select
。然后为所有这些人定义onchange
侦听器:
var urlmenus = document.querySelectorAll('.menu1');
for(var i = 0; i < urlmenus.length; i++) {
urlmenus[i].onchange = function () {
window.open(this.options[this.selectedIndex].value, '_blank', 'width=595,height=842,directories=no,titlebar=no,toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no');
};
}
答案 1 :(得分:1)
输入此代码并尝试
$(document).ready(function () {
$("#menu1").change(function () {
var val1 = $(this).val();
window.open(val1, '_blank');
});
})
&#13;
<form>
<select name="menu1" id="menu1">
<option value="" selected>Pick a Website</option>
<option value="letter/letter_print.php?id=<?php echo $row['id']; ?>">Without Letter Head</option>
<option value="letter/letter_print_nohead.php?id=<?php echo $row['id']; ?>">Letter Head</option>
</select>
</form>
&#13;