我在尝试访问Html表单中的select值时遇到了一些问题。有多个下拉列表,我试图迭代它们以检查它们的值。我已经尝试将我的递增变量附加到结尾,但是在我对js函数checkform()的调用中没有读出它。
<select id="selectcell<?php echo $i;?>"
style="WIDTH: 100px; HEIGHT: 20px" type="text" cellpadding="0" cellspacing="0">
&#13;
Checkform()的
function checkform(){
var a=document.getElementById("selectcell<?php echo $i;?>");
alert(a.options[a.selectedIndex].value);
}
&#13;
答案 0 :(得分:1)
PHP是服务器端,所以php值只会设置一次。你必须使用javascript循环id。
function checkform()
{
for (i = 1; i < <?php echo $MaxValueOfSelects+1); ?>; i++)
{
var a=document.getElementById("selectcell"+i);
alert(a.options[a.selectedIndex].value);
}
}