将递增变量添加到Html Select的Id中


Adding Incrementing Variable to Id of Html Select

当我试图访问Html表单中select的值时,遇到了一些问题。有多个下拉列表,我试图对它们进行迭代以检查它们的值。我曾尝试将递增变量追加到末尾,但在对js函数checkform()的调用中没有读出。

<select id="selectcell<?php echo $i;?>"
 style="WIDTH: 100px; HEIGHT: 20px" type="text" cellpadding="0" cellspacing="0">

Checkform()

function checkform(){
	var a=document.getElementById("selectcell<?php echo $i;?>");
	alert(a.options[a.selectedIndex].value);
}

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);        
    }
}