I have about 20 check boxes. When the user selects these and then uses an alternate submit button, I need to change the name of the name/value pair, for the selected inputs.

我有大约20个复选框。当用户选择这些然后使用备用提交按钮时,我需要更改所选输入的名称/值对的名称。

Why does this function only change the name of every other selected input?

为什么此功能仅更改所有其他所选输入的名称?

function sub_d()
{

    for (i = 0; i < document.checks.OGname.length; i++) //for all check boxes
    {
        if (document.checks.OGname[i].checked == true)
        {
            document.checks.OGname[i].name="newname"; //change name of input 

        }

    }

    document.checks.submit();
}

The output:

newname
    '105' 
OGname
    '106' 
newname
    '107' 
OGname
    '108' 
newname
    '109' 
OGname
    '110' 

3 个解决方案

#1


By renaming the first element of the list you have reduced the length of the list by one and deleted the first element. Next time through the loop the previous second element is now the first, and the second is the old third.

通过重命名列表的第一个元素,您将列表的长度减少了一个并删除了第一个元素。下一次循环时,前一个第二个元素现在是第一个元素,第二个元素是旧的第三个元素。

I'm no javascript expert, but something along the lines of this might work.

我不是javascript专家,但是这可能有用。

function sub_d()
{
  i=0;
  while (document.checks.OGname.length > i)
  {
    if (document.checks.OGname[i].checked="true")
      {
        document.checks.OGname[i].name="newname";
      }else{
        i++;
      }
  }
  document.checks.submit();
}

As I said, no warranty or guarantee.

正如我所说,没有保证或保证。

更多相关文章

  1. HTML哪些是块级元素,哪些是行内元素、
  2. 如何使用CSS消除元素的偏移?
  3. KeyPress或KeyDown事件没有得到html元素的buind
  4. 行内元素与块级元素
  5. 固定定位,父元素具有转换
  6. 在c#中获取html元素的实际边距
  7. 两个堆叠的元素与他们旁边的元素成比例增长
  8. html css伪元素标签(二)灵活
  9. 如何使用Watir访问自定义属性的元素?

随机推荐

  1. ANDROID ADB工具使用
  2. android中eclipse查看源代码
  3. 禁止手机横竖屏
  4. 通过XML设置屏幕方向(android:screenOrie
  5. Android 2.3 r1 中文API (78)—— ViewAnim
  6. Android高效率编码-第三方SDK详解系列(二
  7. Android(安卓)API Guides---Near Field C
  8. android 呼入电话的监听(来电监听)
  9. Android(安卓)11 中的隐私权更新 :存储机
  10. 命令行 android 出 No suitable Java fou