...

View Full Version : show/hide 2 text box on radio selection



Choc
07-19-2012, 07:18 AM
Hii
I have 2 radio buttons and 2 text boxes i need to show/hide them based on radio button selection.. I am totally new to javascript..pls help me

Philip M
07-19-2012, 09:17 AM
Here you are:-


<form>
Button A <input type = "radio" name = "rad1" onclick = "showBox()">
Button B <input type = "radio" name = "rad1" onclick = "showBox()">
<br>
<span id = "span1" style="display:none">Textbox 1 <input type = "text" name = "textbox1"></span>
<span id = "span2" style="display:none">Textbox 2 <input type = "text" name = "textbox2"></span>
</form>

<script type = "text/javascript">

function showBox() {
document.getElementById("span1").style.display="none";
document.getElementById("span2").style.display="none";
if (document.forms[0].rad1[0].checked) {
document.getElementById("span1").style.display="block";
}
if (document.forms[0].rad1[1].checked) {
document.getElementById("span2").style.display="block";
}
}

</script>


If it wasn't for my father, I might not be sitting here today. - Interviewee BBC Radio 4.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum