VBscript/HTML 中的复选框值
Checkbox Value in VBscript/HTML
我创建了一个简单的表单,它使用数组将数据发送到 Excel 文件。
除了复选框,一切都很好。我想要的是,如果复选框是 "checked",它将 post 其值放入 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>
文本框的值为"Checked"或"Unchecked"。如果我正确地理解了您的问题,听起来您想要复制其值的表单上还有另一个文本框(尽管我在您的 HTML 代码中没有看到它;也许您需要添加它?)。类似于:
If Form1.text5.Checked = True Then
arr(6) = Form1.text6.Value 'Or .Text
End If
给复选框命名 "test5" 是一种暴行。看看它对乔什做了什么。
这个
<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>
是 present/discuss 您的问题所需的全部代码。将 Excel 和文本元素拖到问题中是混淆和浪费其他人的时间。
阅读 checkbox element 并进行比较
<input type="checkbox" name="text5" value="checked">
对比
<input type="checkbox" name="cbx" value="pipapo" checked="checked">
应该让您了解 value 和 checked 属性之间的区别。
运行 演示代码将证明 checked 属性设置为 True
或 False
取决于用户(不是)marking/checking 盒子。
参见 this 了解原因
If Form1.text5.Checked = True Then ' <-- nonono
应该是
If Form1.text5.Checked Then
我创建了一个简单的表单,它使用数组将数据发送到 Excel 文件。
除了复选框,一切都很好。我想要的是,如果复选框是 "checked",它将 post 其值放入 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>
文本框的值为"Checked"或"Unchecked"。如果我正确地理解了您的问题,听起来您想要复制其值的表单上还有另一个文本框(尽管我在您的 HTML 代码中没有看到它;也许您需要添加它?)。类似于:
If Form1.text5.Checked = True Then
arr(6) = Form1.text6.Value 'Or .Text
End If
给复选框命名 "test5" 是一种暴行。看看它对乔什做了什么。
这个
<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>
是 present/discuss 您的问题所需的全部代码。将 Excel 和文本元素拖到问题中是混淆和浪费其他人的时间。
阅读 checkbox element 并进行比较
<input type="checkbox" name="text5" value="checked">
对比
<input type="checkbox" name="cbx" value="pipapo" checked="checked">
应该让您了解 value 和 checked 属性之间的区别。
运行 演示代码将证明 checked 属性设置为
True
或False
取决于用户(不是)marking/checking 盒子。参见 this 了解原因
If Form1.text5.Checked = True Then ' <-- nonono
应该是
If Form1.text5.Checked Then