Thank you Alex
--alan
-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Thursday, January 17, 2002 6:59 AM
To: javascript
Subject: [javascript] RE: How to Validate for Only One Radio Button
<INPUT TYPE="RADIO" ... STYLE="visibility:hidden">
-----Original Message-----
From: Alan Chiu [mailto:achiu@m...]
Sent: 16 January 2002 17:19
To: javascript
Subject: [javascript] RE: How to Validate for Only One Radio Button
Alex,
Thank you very much, it works!
But I don't know how to use CSS to hide the radio button. Could you post the
code or point me to the right URLs.
Alan
-----Original Message-----
From: Alex Shiell, ITS, EC, SE [mailto:alex.shiell@s...]
Sent: Wednesday, January 16, 2002 11:16 AM
To: javascript
Subject: [javascript] RE: How to Validate for Only One Radio Button
The problem is that if you have a few radio buttons with the same name you
have a collection, wheras if you have just one you have a sigle object. So
when you have a collection the first one is 'radio[0]', but when you have
just one its just 'radio'.
The quick & easy way to resolve this is to have another radio button with
the same name at the bottom of the page, and use CSS to hide it from view.
That way your first radio button will always be 'radio[0]' regardless of
whether you have one or more. It doesn't matter if it gets checked or
whatever by code becasuse its meaningless anyway.
-----Original Message-----
From: achiu@m... [mailto:achiu@m...]
Sent: 16 January 2002 15:10
To: javascript
Subject: [javascript] How to Validate for Only One Radio Button
Hello Everyone,
I use this simple javascript to validate check radio button:
<script language="javaScript" type="text/javaScript">
<!-- hide script from older browsers
function chkRadioBtn(radio)
{
for (var i=0;i<radio.EventID.length;i++)
{
if (radio[i].checked && radio.value !='')
return true
}
alert ("Please select a radio button.");
return false;
}
// End hiding script -->
</script>
I use getRows() method to retrieve data from a table:
if NOT rsEvent.EOF then
arrEvent = rsEvent.getRows()
'''0=eventid, 1=CourseTitle, 4=Location, 5=Date 6=StartTime, 8=Capacity
for j = 0 to ubound(arrEvent,2)
<td><input type="RADIO" name="EventID" value="<%=arrEvent(0,j)%>"></td>
<td><font face="arial, helvetica" size="2"><%=arrEvent(1,j)%></font></td>
<td><font face="arial, helvetica" size="2"><%=arrEvent(4,j)%></font></td>
<td><font face="arial, helvetica" size="2"><%=arrEvent(5,j)%></font></td>
<td><font face="arial, helvetica" size="2"><%=arrEvent(6,j)%></font></td>
<td><font face="arial, helvetica" size="2"><%=arrEvent(8,j)%></font></td>
<%next%>
If there are more than one radio buttons(more than one course retrieved
from the database), the javascript works well. But if there is only one
radio button it displays the alert message "Please select a radio button."
Any help will be appreciated.
Alan
________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com
Headquarters Address & Contact Numbers
150 Broomielaw
5 Atlantic Quay
Glasgow
G2 8LU.
Tel: +44 (0) 141 248 2700.
Fax: +44 (0)141 221 3217
This message is sent in confidence for the addressee only.
It may contain legally privileged information. The contents are not to
be disclosed to anyone other than the addressee. Unauthorised recipients
are requested to preserve this confidentiality and to advise the sender
immediately of any error in transmission.
________________________________________________________________________
Scottish Enterprise Network
http://www.scottish-enterprise.com
Headquarters Address & Contact Numbers
150 Broomielaw
5 Atlantic Quay
Glasgow
G2 8LU.
Tel: +44 (0) 141 248 2700.
Fax: +44 (0)141 221 3217
This message is sent in confidence for the addressee only.
It may contain legally privileged information. The contents are not to
be disclosed to anyone other than the addressee. Unauthorised recipients
are requested to preserve this confidentiality and to advise the sender
immediately of any error in transmission.