【问题标题】:Checkbox Value in VBscript/HTMLVBscript/HTML 中的复选框值
【发布时间】:2015-05-12 18:25:19
【问题描述】:

我创建了一个简单的表单,它将数据发送到带有数组的 Excel 文件。 除了复选框,一切都很好。我想要的是,如果复选框被“选中”,它将把它的值发布到 Excel 文档中。目前,无论是否选中,始终粘贴为框(选中)分配的值。我不确定arr(6) 需要什么代码。

<script>
  function PrintFunction() {
      window.print();
  }
</script>

<script type="text/vbscript">
  function test()
    dim oApp, oWB, arr
    set oApp = CreateObject("Excel.Application")
    oApp.visible=false
    set wb = oApp.Workbooks.Open("C:\(PATH TO DB)\DB.xls",,,,"password")
    redim arr(6)

    arr(0) = Date()
    arr(1) = Form1.text1.Value
    arr(2) = Time()
    arr(3) = Form1.text2.Value
    arr(4) = Form1.text3.Value
    arr(5) = Form1.text4.Value
    arr(6) = Form1.text5.Value  <---Need help with this value

    with wb.sheets("Data").cells(1,1).currentregion
      .offset(.rows.count,0).resize(1).value = arr
    end with
    wb.close true

  x=msgbox("Submitted." ,64, "Thank you.")

    window.close()

  end function
</script>
</head>

<body oncontextmenu="return false;"> 
<form name="Form1">
<table border="0" style="width:700px;">
<td>Date:<input value="mm/dd/yyyy" name="text1" type="text" class="inputbox" size="20" />
<tr>
<td>Time:<input value="00:00 AM/PM" name="text2" type="text" class="inputbox" size="20" /></td>
<tr>
<td>Name:<input name="text3" type="text" class="inputbox" size="23"/></td>
<tr>
<td>Location:<input name="text4" type="text" class="inputbox" size="18" /></td>
<tr>
<td><input type="checkbox" name="text5" value="checked">Checkbox Title</td>
<input type="button" value="Print" class="classname" onclick="PrintFunction()" />
<input type="button" value="Submit" class="classname" onclick="test()" />
</table>
<br>
</form>

【问题讨论】:

    标签: html excel vbscript


    【解决方案1】:
    1. 将复选框命名为“test5”是一种暴行。看看它对乔希做了什么。

    2. 这个

      <html>
       <head>
        <hta:application id = "cbxproblem">
        <script type="text/vbscript">
         function test()
           MsgBox Form1.cbx.checked ' <---Need help with this value
           MsgBox Form1.cbx.value
         end function
        </script>
       </head>
       <body>
        <form name="Form1">
          <input type="checkbox" name="cbx" value="pipapo" checked="checked">Checkbox Title
          <hr />
          <input type="button" value="Submit" onclick="test()" />
        </form>
       </body>
      </html>
      

      是呈现/讨论您的问题所需的所有代码。将 Excel 和文本元素拖入问题中会混淆并浪费其他人的时间。

    3. 阅读checkbox element并进行比较

      <input type="checkbox" name="text5" value="checked">
      

      对比

      <input type="checkbox" name="cbx" value="pipapo" checked="checked">
      

      应该让你意识到 valuechecked 属性之间的区别。

    4. 运行演示代码将证明 checked 属性设置为 TrueFalse,具体取决于用户(未)标记/选中框。

    5. 请参阅this 了解原因

      If Form1.text5.Checked = True Then ' <-- nonono
      

      应该是

      If Form1.text5.Checked Then
      

    【讨论】:

    • 感谢所有输入和示例。我宁愿告诉别人我所做的一切,以便他们提前了解全貌。这对你来说可能是浪费时间,但对其他人来说可能不是。没有理由如此敌对。
    【解决方案2】:

    文本框的值为“选中”或“未选中”。如果我正确理解您的问题,听起来表单上有另一个文本框,您要复制其值(尽管我在您的 HTML 代码中没有看到它;也许您需要添加它?)。比如:

    If Form1.text5.Checked = True Then
        arr(6) = Form1.text6.Value  'Or .Text
    End If
    

    【讨论】:

    • 乔希这有帮助。谢谢你。我将 text6 的值改回 5 并且它起作用了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-17
    • 2012-10-06
    • 2019-05-02
    • 1970-01-01
    相关资源
    最近更新 更多