Hi every one. I have two radio buttons, yes and no. Then I have some input boxes below. If someone selects yes, they get input box 1, if they select no they get input boxes 2,3,4,5.
I am very new to javascript, can someone please help
It sounds more like you want to hide/show the inputs rather than enable/disable them.
Create your radio buttons both with the same name. Create two divs with unique IDs and put your input boxes inside them:
The onclick event of the radio buttons points to the chgOptions function below. This function determines which radio button was clicked and toggles the display attribute of the appropriate div.
Code:
<script type="text/javascript">
function chgOptions() {
var myradio = document.getElementsByName('R1');
if (myradio[0].checked) {
document.getElementById('optgrp1').style.display = 'inline';
document.getElementById('optgrp2').style.display = 'none';
}
else {
document.getElementById('optgrp1').style.display = 'none';
document.getElementById('optgrp2').style.display = 'inline';
}
}
</script>
Put the script block inside the head of your document.
At my age I still learn something new every day, but I forget two others.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.