Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-19-2012, 06:18 AM   PM User | #1
Choc
New to the CF scene

 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Choc is an unknown quantity at this point
show/hide 2 text box on radio selection

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
Choc is offline   Reply With Quote
Old 07-19-2012, 08:17 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Here you are:-

Code:
<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.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:21 AM.


Advertisement
Log in to turn off these ads.