VBscript / HTML中的checkbox值

我创build了一个简单的表单,它将数据发送到Excel文件。 除了checkbox,一切都很好。 我想要的是,如果checkbox被“检查”,它会将其值发布到Excel文档中。 目前,为框(勾选)分配的值总是被粘贴,而不pipe是否被勾选。 我不确定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> 

文本框的值是“选中”或“未选中”。 如果我正确地理解了你的问题,听起来好像表单上有另一个你想要复制的文本框(尽pipe我没有在你的HTML代码中看到它,也许你需要添加它)。 就像是:

 If Form1.text5.Checked = True Then arr(6) = Form1.text6.Value 'Or .Text End If 
  1. 命名checkbox“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元素和比较

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

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

    应该让你意识到检查属性之间的差异。

  4. 运行演示代码将certificatechecked属性被设置为TrueFalse具体取决于用户(不)标记/检查框。

  5. 看到这个了解为什么

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

    应该

     If Form1.text5.Checked Then