TBor
05-30-2003, 11:45 AM
OK, hello again to everyone. This is an odd one, hopefully someone here can help me.
I've got an ASP script that generates a group of radio buttons. These radio buttons all have the same name/id, but different values.
On a certain event, I want to check the group of radio buttons to see which one is selected. I have no problem writing the "For" loop to handle this. However, because of how the group of radio buttons is generated, there is a very real possibility that the "group" will consist of only 1 radio button. This messes up my "for" loop, as I can't check the Length property of a group of 1 radio button.
Here's an example of what I mean:
<script language="VBScript">
sub Click
set radiogroup = document.formname.radioname
for i=0 to radiogroup.length
if radiogroup(i).checked then
RadioVal = radiogroup(i).value
exit for
end if
next
end sub
</script>
...
<form name="formname">
<input type="radio" name="radioname" value="1">
<input type="radio" name="radioname" value="2">
<input type="radio" name="radioname" value="3">
<input type="button" onClick="Click">
</form>
In the script above, radiogroup.length = 3. However, if my form looked like this (which is possible in my code):
<form>
<input type="radio" name="radioname" value="1">
<input type="button" onClick="Click">
</form>
...then I get the error "VBScript Runtime Error: Object doesn't support this property or method: 'radiogroup.length' was not handled". This error is not limited to the Length property - if I change the For loop to "For i=1 to 100"', I still get an error on all lines containing "radiogroup(i)" (I guess that's because radiogroup is not a group in this case)
I'm using radio buttons here because I need to ensure only 1 of the items in the group is selected at any one time, no matter if the group has 1 element or 1000 elements.
So, after all that description, my question:
(1) is there a way to detect if my radio button group only has 1 button in it? If so, I could use an if...else structure for handling the 1 button...many buttons situations.
(2) if #1 is no, then can anyone think of another way to give me the functionality of the radio button (only 1 checked at a time) without using radio buttons?
Hopefully I've explained myself well enough here. Thanks in advance for your help.
Thanks,
TBor
I've got an ASP script that generates a group of radio buttons. These radio buttons all have the same name/id, but different values.
On a certain event, I want to check the group of radio buttons to see which one is selected. I have no problem writing the "For" loop to handle this. However, because of how the group of radio buttons is generated, there is a very real possibility that the "group" will consist of only 1 radio button. This messes up my "for" loop, as I can't check the Length property of a group of 1 radio button.
Here's an example of what I mean:
<script language="VBScript">
sub Click
set radiogroup = document.formname.radioname
for i=0 to radiogroup.length
if radiogroup(i).checked then
RadioVal = radiogroup(i).value
exit for
end if
next
end sub
</script>
...
<form name="formname">
<input type="radio" name="radioname" value="1">
<input type="radio" name="radioname" value="2">
<input type="radio" name="radioname" value="3">
<input type="button" onClick="Click">
</form>
In the script above, radiogroup.length = 3. However, if my form looked like this (which is possible in my code):
<form>
<input type="radio" name="radioname" value="1">
<input type="button" onClick="Click">
</form>
...then I get the error "VBScript Runtime Error: Object doesn't support this property or method: 'radiogroup.length' was not handled". This error is not limited to the Length property - if I change the For loop to "For i=1 to 100"', I still get an error on all lines containing "radiogroup(i)" (I guess that's because radiogroup is not a group in this case)
I'm using radio buttons here because I need to ensure only 1 of the items in the group is selected at any one time, no matter if the group has 1 element or 1000 elements.
So, after all that description, my question:
(1) is there a way to detect if my radio button group only has 1 button in it? If so, I could use an if...else structure for handling the 1 button...many buttons situations.
(2) if #1 is no, then can anyone think of another way to give me the functionality of the radio button (only 1 checked at a time) without using radio buttons?
Hopefully I've explained myself well enough here. Thanks in advance for your help.
Thanks,
TBor