使用javascript验证从php到html的下拉列表?

使用javascript验证从php到html的下拉列表?,php,javascript,mysql,html,forms,Php,Javascript,Mysql,Html,Forms,好吧,这个问题的标题可能有点让人困惑,我会试着向你们解释: 我有一个包含多个表单字段的数组的php文件,如下所示: $var = array(0 => '<input type=....>', 1=> '<input type=....>'); echo '<table>'; while($row = mysql_fetch_array($result)){ $num = $row['fieldId']; $field = $

好吧,这个问题的标题可能有点让人困惑,我会试着向你们解释: 我有一个包含多个表单字段的数组的php文件,如下所示:

$var = array(0 => '<input type=....>', 1=> '<input type=....>');
echo '<table>';
  while($row = mysql_fetch_array($result)){
    $num = $row['fieldId'];
    $field = $num.' '.$row['field'];
    echo '<tr><td>'.$field.'</td>';
    echo '<td>'.$var[$q].'</td></tr>';
    echo '<tr><td>&nbsp;</td></tr>';
    $q++;
  }; echo '</table>';
这就是函数所做的,除了我添加注释的那个条件外,所有条件都有效。(我还在学习,所以请不要嘲笑我的代码。)

很抱歉,我实际解决了这个问题,我的php数组中的html代码中有一些错误。现在它真的起作用了。
谢谢。

这是在javascript中访问选择值的方式:

<form name="mainform">
    <select name="dropbox_select">
        <option value="value0">option0</option>
        <option value="value1">option1</option>
        <option value="value2">option2</option>
    </select>
</form>

document.forms.mainform.dropbox_select.options[0].value
document.forms.mainform.dropbox_select.options[1].value
document.forms.mainform.dropbox_select.options[2].value

选项0
选择1
选择2
document.forms.mainform.dropbox\u select.options[0]。值
document.forms.mainform.dropbox\u select.options[1]。值
document.forms.mainform.dropbox\u select.options[2]。值

您可以发布有问题的select元素的解析代码吗?您正在通过id或使用一些jquery魔术获得select标记?(如果你发布一些代码,会很有帮助)如果javascript验证是个问题,你可能想发布代码,这与PHP无关。把整页贴在某个地方,让我们看看。
function myFunctionNameHere(){
if(!document.mainForm.p1_1[0].checked && !document.mainForm.p1_1[1].checked)
      alert("1 - some warning here");
    else if(!document.mainForm.p1_2[0].checked && !document.mainForm.p1_2[1].checked)
      alert("2 - some warning here");
    else if(!document.mainForm.p1_3[0].checked && !document.mainForm.p1_3[1].checked)
      alert("3 - some warning here");
    else if(!document.mainForm.p1_4[0].checked && !document.mainForm.p1_4[1].checked)
      alert("4 - some warning here");
    else if(!document.mainForm.p1_5[0].checked && !document.mainForm.p1_5[1].checked)
      alert("5 - some warning here");
    else if(!document.mainForm.p1_6[0].checked && !document.mainForm.p1_6[1].checked)
      alert("6 - some warning here");
    else if(document.mainForm.p1_7.value == "")
      alert("7 - some warning here");
    // this condition does not work:
    else if(document.mainForm.p1_8.selectedIndex == 0)
      alert("8 - some warning here);
   // can't get the selectd field from the html select field
    else
      window.location = "OTHERPAGE.html";
}
<form name="mainform">
    <select name="dropbox_select">
        <option value="value0">option0</option>
        <option value="value1">option1</option>
        <option value="value2">option2</option>
    </select>
</form>

document.forms.mainform.dropbox_select.options[0].value
document.forms.mainform.dropbox_select.options[1].value
document.forms.mainform.dropbox_select.options[2].value