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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

loop to disable radio buttons

Status
Not open for further replies.

jamica

Programmer
Apr 25, 2005
17
GB
I have the follwoing javascript(the html's below)...... I am trying to disable the radio buttons in all radio groups which will total to more than 4 i've managed to get it to get a total of 4 but i now need to disable the radio buttons which will give a higher value than 4 ie if 3 is checked then the user should only be able to select 1 from the rest of the questions....

how do I get it to loop and disable all radio options which will total to more than 4?

thanks

Code:
<script language="JavaScript" type="text/javascript">

// function which works onClick of a radio button to find out which radio buttons to make void 
function workOutSpotsAvail()
{
	//array to hold the available radio buttons 
	var spotsA	vail = new Array(4, 4, 4, 4);
	var valChecked = 0;

	// Loop through question
	for(option=0; option<4; i++)
	{
		// work out the value checked
		for(optionVal=1; optionVal<=4; optionVal++)
		{
			var currentRadio = getelementbyid("ol_" + option + "_" + optionVal);
			if(currentRadio.checked())
			{
				valChecked = optionVal;
				break;
			}
		}
		
		// Remove value from other options
		if(valChecked > 0)
		{
			for(i=0; i<4; i++)
			{
				if(i != option) spotsAvail[i] = spotsAvail[i] - valChecked;
			}
		}
	
	}
	greyOut(spotsAvail);
} 

// disables the radio buttons which are rendered in the last function 	
function greyOut(spotsArray) {
	


}

the html

Code:
   <form name="forms" id="forms" method="post" action="3.php" onsubmit="return validate()">

      <input type="radio" name="o1" id="o1_1" value="1" class="check1" onclick="workOutSpotaAvail(1, 1)" />
        <input type="radio" name="o1" id="o1_2" value="2" class="check2" onclick="workOutSpotaAvail(1, 2)" />
        <input type="radio" name="o1" id="o1_3" value="3" class="check3" onclick="workOutSpotaAvail(1, 3)" />
        <input type="radio" name="o1" id="o1_4" value="4" class="check4" onclick="workOutSpotaAvail(1, 4)" />
        <br />


       <input type="radio" name="o2" id="o2_1" value="1" class="check1" onclick="workOutSpotaAvail(2, 1)" />
        <input type="radio" name="o2" id="o2_2" value="2" class="check2" onclick="workOutSpotaAvail(2, 2)" />
        <input type="radio" name="o2" id="o2_3" value="3" class="check3" onclick="workOutSpotaAvail(2, 3)" />
        <input type="radio" name="o2" id="o2_4" value="4" class="check4" onclick="workOutSpotaAvail(2, 4)" />
        <br />

        <input type="radio" name="o3" id="o3_1" value="1" class="check1" onclick="workOutSpotaAvail(3, 1)" />
        <input type="radio" name="o3" id="o3_2" value="2" class="check2" onclick="workOutSpotaAvail(3, 2)" />
        <input type="radio" name="o3" id="o3_3" value="3" class="check3" onclick="workOutSpotaAvail(3, 3)" />
        <input type="radio" name="o3" id="o3_4" value="4" class="check4" onclick="workOutSpotaAvail(3, 4)" />
        <br />


       <input type="radio" name="o4" id="o4_1" value="1" class="check1" onclick="workOutSpotaAvail(4, 1)" />
        <input type="radio" name="o4" id="o4_2" value="2" class="check2" onclick="workOutSpotaAvail(4, 2)" />
        <input type="radio" name="o4" id="o4_3" value="3" class="check3" onclick="workOutSpotaAvail(4, 3)" />
        <input type="radio" name="o4" id="o4_4" value="4" class="check4" onclick="workOutSpotaAvail(4, 4)" />
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top