在提交表单之前,组合框选择了值更改

时间:2012-10-17 07:23:44

标签: c web combobox cgi

我使用CGI C并尝试在表单中使用组合框。当我更改所选值并按下保存按钮时,在提交表单之前,我可以看到所选值发生变化。它总是变成7。我找不到原因。这是我的代码:

<form method=POST action="cgi-bin/aa.cgi?aa.xml" name="aform" onsubmit="return checkConForm(document.aform);">
    <table class=conftable>
            <td class=conftabletd>
            <select name="aa" id="aa" >
            <option value=2>2</option><option>1</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option>
            </select></td>
        </tr>
    </table><br>
    <a href="javascript:submitform(document.aform)" class="more">save</a>
</form> 

js:

function checkConfigForm ( form )
{

   var selectLists = document.getElementsByTagName("select");
   for ( var i=0; i<selectLists.length; i++ ) {
       if (selectLists[i].id != null) {
         alert(selectLists[i].id);
         selectOpts(selectLists[i].id);
        }
    }
    return true;
}

function selectOpts( selectId )
{
  var selectList = document.getElementById(selectId);
  var selectListLength = selectList.length;
  if (selectListLength == 0){
    appendOptionLastwValue( selectId, "" );
    selectListLength = 1;
  }
  for (var i = 0; i < selectListLength; i++) {
    selectList.options[i].selected = true;
  }
  return true;
}


function submitform( form )
{
     if(form.onsubmit() == true){
     form.submit();
} 

1 个答案:

答案 0 :(得分:0)

显然,您将SELECT对象的每个选项一个接一个地设置为TRUE:

for (var i = 0; i < selectListLength; i++) {
    selectList.options[i].selected = true;
}

提交表格后,最后一个选项(选项[6] = 7)被选为结果。