Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Buttons & JavaScript

Status
Not open for further replies.

joebankz

Programmer
Jun 13, 2001
8
0
0
US
I am trying to create a script that turns off the 'disabled' attribute in a set of radio buttons when another radio button elsewhere is clicked.

To see this code in context find the disabled radio buttons on this page:
Code:
<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot; TYPE=&quot;TEXT/JAVASCRIPT&quot;>
<!--
Function EnableDots(MonthlyOption) {
	If (MonthlyOption.checked) {
		for (i=0; i<document.AddEvent.D.length; i++) {
		document.AddEvent.D[i].disabled = false 
		}
		document.AddEvent.D[i].disabled = true
	}
//-->
</SCRIPT>
.....
<label for=&quot;Monthly&quot;> 
--    <input type=&quot;radio&quot; name=&quot;RepID&quot; value=&quot;2&quot; id=&quot;Monthly&quot; OnClick=&quot;EnableDots(this);&quot;>
    every month on<br>
    </label> 
  <table width=&quot;400&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;2&quot;>
    <tr> 
      <td width=&quot;10&quot;> </td>
      <td width=&quot;382&quot;> 
        <label for=&quot;emonth1&quot;><input id=&quot;emonth1&quot; type=&quot;radio&quot; name=&quot;D&quot; value=&quot;1&quot; DISABLED>
        The first  of every month</label> </td>
    </tr>
    <tr> 
      <td width=&quot;10&quot;> </td>
      <td width=&quot;382&quot;> 
        <label for=&quot;emonth2&quot;><input id=&quot;emonth2&quot; type=&quot;radio&quot; name=&quot;D&quot; value=&quot;2&quot; DISABLED>
        The second  of every month</label> </td>
    </tr>
    <tr> 
      <td width=&quot;10&quot;>  </td>
      <td width=&quot;382&quot;> 
        <label for=&quot;emonth3&quot;><input id=&quot;emonth3&quot; type=&quot;radio&quot; name=&quot;D&quot; value=&quot;3&quot; DISABLED>
        The third  of every month</label></td>
    </tr>
    <tr> 
      <td width=&quot;10&quot;>  </td>
      <td width=&quot;382&quot;> 
        <label for=&quot;emonth4&quot;><input id=&quot;emonth4&quot; type=&quot;radio&quot; name=&quot;D&quot; value=&quot;4&quot; DISABLED>
        The fourth  of every month</label></td>
    </tr>
    <tr> 
      <td width=&quot;10&quot;>  </td>
      <td width=&quot;382&quot;> 
        <label for=&quot;emonth5&quot;><input id=&quot;emonth5&quot; type=&quot;radio&quot; name=&quot;D&quot; value=&quot;5&quot; DISABLED>
        The fifth  of every month</label></td>
    </tr>
    <tr> 
      <td width=&quot;10&quot;>  </td>
      <td width=&quot;382&quot;> 
        <label for=&quot;emonth0&quot;><input id=&quot;emonth0&quot; type=&quot;radio&quot; name=&quot;D&quot; value=&quot;0&quot; DISABLED>
        The  of every month</label></td>
    </tr>
  </table>
 
Hi,

Take a look at this example:-

<html>
<head><title>Radio test</title></head>
<script language=&quot;javascript&quot;>
function ss(){
alert(document.Form1.loc[0].disabled);
var abc=&quot;false&quot;;
for (var i=0;i<document.Form1.loc.length;i++) {
if (document.Form1.loc.checked) {
abc = document.Form1.loc.value;
break;
}
}
if (abc == &quot;false&quot;)
alert(&quot;Please select a radio button.&quot;);
else
alert(&quot;You have selected : &quot;+abc);
}
function enableRB(){
document.Form1.loc1[0].disabled = false;
document.Form1.loc1[1].disabled = false;
document.Form1.loc1[2].disabled = false;
}
</script>
<body onload=&quot;disableRB()&quot;>
<form name=&quot;Form1&quot;>
<INPUT type=radio name=&quot;loc&quot; value=&quot;blah1&quot;> blah1 <BR>
<INPUT type=radio name=&quot;loc&quot; value=&quot;blah2&quot;> blah2 <BR>
<INPUT type=radio name=&quot;loc&quot; value=&quot;blah3&quot; onclick=&quot;enableRB();&quot;> Click me to enable group 2 <BR><br><br><br>

<INPUT type=radio name=&quot;loc1&quot; value=&quot;blah4&quot; disabled> blah4 <BR>
<INPUT type=radio name=&quot;loc1&quot; value=&quot;blah5&quot; disabled> blah5 <BR>
<INPUT type=radio name=&quot;loc1&quot; value=&quot;blah6&quot; disabled> blah6 <BR>


<input type=&quot;button&quot; value=&quot;Click&quot; onclick=&quot;ss();&quot; >
</form>
</body></html>

It seems that NS doesn't support the disabling of radio buttons until version 6? If you want to cater for NS 4, take a look at this link:-


Regards,
Leon If you need additional help, you can email to me at zaoliang@hotmail.com I don't guaranty that I will be able to solve your problems but I will try my best :)
 
hiee!

joe, here is your function that works in ie5.0:

function EnableDots(obj) {
if (obj.value==2){
for (ii=0; ii<document.AddEvent.D.length; ii++) {
document.AddEvent.D[ii].disabled = false }
}
else{
for (ii=0; ii<document.AddEvent.D.length; ii++) {
document.AddEvent.D[ii].disabled = true }
}
}

& u are 2 call it from every radio named RepID
just like u call it from where the value eq 2. (i looked on site u pointed, there is the only one call for this function, mistake)

regards, Vic
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top