form - radio button check - javascript

Hi all,
I have a form with 2 different radio elements. First radio button is a yes no question. if yes selected nothing happens, however if no is selected, other radio button is activated (has 4 radio buttons should be selected). My question is, I can initially select a value on this field however if I click on yes (on the first radio button) and click on no (again in the first radio button) it doesnt select any value automatically. Is it possible to select a value everytime no is clicked on the first radio button? thanks in advance
LVL 5
cempashaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
This makes no sense:
>>... other radio button is activated (has 4 radio buttons should be selected).
radio buttons are mutually exclusive. It seems you are using the term radio button for select lists, radio buttons and checkboxes interchangeably. These are different elements and actually make a difference when it comes to programming. Clarify or better yet, post the code that you have.
0
cempashaAuthor Commented:
I've attached a working example. You can try this one and see what I'm trying to do. I hope this helps
<SCRIPT LANGUAGE="JavaScript">
 
function Disab (val) {
if(val=="1")
{
theForm.gr12[0].disabled=true;theForm.gr12[0].checked=false;
theForm.gr12[1].disabled=true;theForm.gr12[1].checked=false;
theForm.gr12[2].disabled=true;theForm.gr12[2].checked=false;
theForm.gr12[3].disabled=true;theForm.gr12[3].checked=false}
 
 
if(val=="2")
{
theForm.gr12[0].disabled=false;
theForm.gr12[1].disabled=false;
theForm.gr12[2].disabled=false;
theForm.gr12[3].disabled=false}
}
</SCRIPT>
 
 
<form name="theForm"> 
<input type="radio" name="gr1" value="1" onClick="Disab(1)">
                                  Yes
                                  <input name="gr1" type="radio" onClick="Disab(2)" value="0">
<table> 
 <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink1" for="fkInternetLink1">link1 </td>
                                <td><input type="radio" name="gr12" value="1" disabled></td>
                              </tr>
                              <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink2" for="fkInternetLink2">link2**</td>
                                <td><input type="radio" name="gr12" value="2" disabled checked></td>
                              </tr>
                              <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink3" for="fkInternetLink3">link3*</td>
                                <td><input type="radio" name="gr12" value="3" disabled></td>
                              </tr>
                              <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink4" for="fkInternetLink4">link4</td>
                                <td><input type="radio" name="gr12" value="4" disabled></td>
                              </tr>
</table>
</form> 

Open in new window

0
hieloCommented:
>> Is it possible to select a value everytime no is clicked on the first radio button
In that case you are better not setting the checked=false on the first if clause. I commented out the "problematic" statements. See code below:

<SCRIPT LANGUAGE="JavaScript">
 var lastChecked = 0;
function Disab (val) 
{
	if(val=="1")
	{
		theForm.gr12[0].disabled=true;//theForm.gr12[0].checked=false;
		theForm.gr12[1].disabled=true;//theForm.gr12[1].checked=false;
		theForm.gr12[2].disabled=true;//theForm.gr12[2].checked=false;
		theForm.gr12[3].disabled=true;//theForm.gr12[3].checked=false
	}
 
 
	if(val=="2")
	{
		
		theForm.gr12[0].disabled=false;
		theForm.gr12[1].disabled=false;
		theForm.gr12[2].disabled=false;
		theForm.gr12[3].disabled=false;
	}
}
</SCRIPT>
 
 
<form name="theForm"> 
<input type="radio" name="gr1" value="1" onClick="Disab(1)">
                                  Yes
                                  <input name="gr1" type="radio" onClick="Disab(2)" value="0"> No
<table> 
 <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink1" for="fkInternetLink1">link1 </td>
                                <td><input type="radio" name="gr12" value="1" disabled></td>
                              </tr>
                              <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink2" for="fkInternetLink2">link2**</td>
                                <td><input type="radio" name="gr12" value="2" disabled checked></td>
                              </tr>
                              <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink3" for="fkInternetLink3">link3*</td>
                                <td><input type="radio" name="gr12" value="3" disabled></td>
                              </tr>
                              <tr>
                                <td><label style="color: rgb(102, 102, 102);" id="lblInternetLink4" for="fkInternetLink4">link4</td>
                                <td><input type="radio" name="gr12" value="4" disabled></td>
                              </tr>
</table>
</form>  
 
 
   

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cempashaAuthor Commented:
one word for you.
perfect
thanks very much :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.