提交表单之前组合框选定的值发生更改

标签 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();
} 

最佳答案

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

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

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

关于提交表单之前组合框选定的值发生更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12929174/

相关文章:

c - 当使用数组标识单个结构时,使用函数更改 typedef 字段

node.js - 如何检查用户是否有数据库查询权限?

javascript - 从数组中过滤掉特定值

javascript - Node 应用程序架构 : where does express come into node. js

python - 更新 PyGTK 组合框时如何保留选择?

c - 将字符串传递给 char* 时出现警告 359

c - 如何将 "float"变量分解为四个字节?

c - 链接我用 pthread 库编写的库

c# - ComboBox.SelectedValue 在 Form 的构造函数中为 null

c++ - 如何在 winapi C++ 上创建一些基本控件,如列表框