Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
148
rated 0 times [  151] [ 3]  / answers: 1 / hits: 20999  / 12 Years ago, tue, october 2, 2012, 12:00:00

very new to javascript, but any help to get me started would be appreciated. I have a simple form:



<div><input type=radio name=o1 id=burger />Burger</div>
<div id=yesFries><input type=checkbox name=e1 id=fries />Fries with that?</div>
<div><input type=radio name=o1 id=pizza />Pizza</div>
<div><input type=radio name=o1 id=hotdog />Hot Dog</div>


I want the Fries checkbox greyed out unless the Burger radio button is selected. I'm not sure if Javascript or CSS is the best way to do it. Thanks in advance!


More From » css

 Answers
23

I've noticed that you don't specify whether or not you can use jQuery. If that's an option, please see one of the other posts as I highly recommend it.



If you cannot use jquery then try the following:



<script>
function setFries(){
var el = document.getElementById(burger);
if(el.checked)
document.getElementById(fries).disabled = false;
else
document.getElementById(fries).disabled = true;
}
</script>


<div><input type=radio name=o1 id=burger onchange=setFries();/>Burger</div>
<div id=yesFries><input type=checkbox name=e1 id=fries disabled=disabled/>Fries with that?</div>
<div><input type=radio name=o1 id=pizza onchange=setFries();/>Pizza</div>
<div><input type=radio name=o1 id=hotdog onchange=setFries();/>Hot Dog</div>​


Simple example on jsFiddle


[#82791] Monday, October 1, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dominics

Total Points: 424
Total Questions: 99
Total Answers: 107

Location: South Korea
Member since Fri, Sep 11, 2020
4 Years ago
dominics questions
Wed, Apr 6, 22, 00:00, 2 Years ago
Thu, Jan 13, 22, 00:00, 2 Years ago
Fri, Sep 18, 20, 00:00, 4 Years ago
;