How can vbscript retrieve the "value" of selected html radio butto

G

Guest

Hi all,

I am currently writing an application involving html and vbscript. I am
building a simple html page for data acquisition, and utilize vbscript to
retrieve the data for further calculation (This html page is not posted on
web and only used on another software program). When I am dealing with html
radio button, I couldn't find a way to retrieve the "value" property of the
selected button during run time. Below are code that I use.

*****vbscript code*******
Sub OnOk() '// When click OK button, I try to retrieve "value" of selected
radio button

Dim sResult

sResult = rButtonGroup1.value '//At run time, error rappears at this line

window.returnValue = sResult

window.close

End Sub


********html code, 2 radio button*******

<input type="radio" value="V1" name="rButtonGroup1">
<input type="radio" value="V2" name="rButtonGroup1">

When I issue the OK button, error message "object does not support this
method or property" 'rButtonGroup1.value' appears. While I expect
"rButtonGroup.value" should return either value V1 or V2. Can anyone give me
some advice about this?

Thanks for your kind attention

Schuey
 
M

MD Websunlimited

Hi Schuey,

You have to walk the array looking for the checked element.

sub findradio_click()

dim i


for i = 0 to document.radiofind.group1.length - 1

if document.radiofind.group1(i).checked then

msgbox document.radiofind.group1(i).value

end if

next

end sub
 
G

Guest

Dear Mike,

Thanks for your help, it works and my problem is basically solved.

Just something I don't understand. I found that method
"document.radiofind." is not supported , therefore, I take off all
"document.radiofind."and use code like Group1(0).checked, Group1(0).value .
Obviously, method Group1.length is not supported. This makes the For...Next
statement a bit awkward since I have to hardcode the loop number. I also
tried Group1().length but still not succeed. Are there any alternative way
to retrieve gourp length? Following is code that involves.

<script LANGUAGE="VBScript">

Sub OnOk()

for i = 0 to 2 '\\Hardcode loop number for 3 radio button

if group11(i).checked then

msgbox group1(i).value

window.returnValue = group1(i).value

end if

next

window.close

End Sub

</script>

<table CELLPADDING="1" CELLSPACING="2" BORDER="0">

<input type="radio" value="Value 1" name="group1">
<input type="radio" value="Value 2" name="group1">
<input type="radio" value="Value 3" name="group1">

</table>

Thanks a lot

Schuey

"MD Websunlimited" 來函:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top