VBS中的单选按钮值

时间:2013-05-11 11:58:46

标签: forms function checkbox vbscript radio

我正在尝试读取VBS中单选按钮的值,我想出现以下错误:

类型不匹配:'阶段'

在我将单选按钮放在表单中以启用/禁用复选框后,我收到此错误,具体取决于第一个单选按钮。

非常感谢任何帮助!

我的代码(不是整个代码,只是错误的部分。通过按钮运行Sub RunScript):

<head>
</head>

<SCRIPT LANGUAGE="VBScript">

Sub RunScript

Dim currentphase

If phase(0).Checked Then
currentphase = phase(0).Value
End If

If phase(1).Checked Then
currentphase = phase(1).Value
End If


If currentphase = "" Then
MsgBox "Please select the phase.",48,"Error"
Exit Sub
End If

End Sub


</SCRIPT>

<body>
<form name="phaseform" action="" >
<input type="radio" name="phase" value="1" id="phase" onclick="checkbox(0)"/><label for="phase1">Phase 1</label>
<input disabled id=inorout type="checkbox" name="InorOUT" value="IN">LEGAL HOLD (<a href=javascript:RunLogFile()>?</a>) <br>
input type="radio" name="phase" value="2" id="phase" onclick="checkbox(1)" /><label for="phase2">Phase 2 (after 17 days)</label>
</form>

<script type="text/javascript">

function checkbox(val)
{
    if(val)
document.phaseform.InorOUT.setAttribute("disabled",val)
else
document.phaseform.InorOUT.removeAttribute("disabled",val)
}
</script>

</BODY>

3 个答案:

答案 0 :(得分:1)

试试这个,它对我有用。

Sub RunScript
    Dim currentphase
    If phaseform.phase(0).Checked Then
        currentphase = phaseform.phase(0).Value
    End If
    If phaseform.phase(1).Checked Then
        currentphase = phaseform.phase(1).Value
    End If
    If currentphase = "" Then
        MsgBox "Please select the phase.",48,"Error"
        Exit Sub
    End If
End Sub

答案 1 :(得分:1)

通过替换阶段(0)解决。使用document.phaseform.phase(0)检查。检查

另一种方式: http://us.generation-nt.com/answer/how-can-vbscript-retrieve-value-selected-html-radio-butto-help-151913911.html

Dim i

for i = 0 to document.phaseform.phase.length - 1
if document.phaseform.phase(i).checked then
currentphase = document.phaseform.phase(i).value
end if

next

答案 2 :(得分:0)

您应首先清理HTML部分(格式不正确的标签等):请参阅以下更正的

<form name="phaseform" action="">
    <input type="radio" name="phase" value="1" id="phase" onclick="checkbox(0)" />
    <label for="phase1">Phase 1</label>
    <input type="checkbox" disabled id="InorOUT" name="InorOUT" value="IN" />LEGAL HOLD (<a href=javascript:RunLogFile()>?</a>)
    <br>
    <input type="radio" name="phase" value="2" id="phase" onclick="checkbox(1)" />
    <label for="phase2">Phase 2 (after 17 days)</label>
</form>

其次,我建议在一个页面中使用javascript而不是组合vbscript / javascript。