Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 2nd, 2005, 11:17 PM
Authorized User
 
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default Toggle active state of textbox with a radio button

I have 5 radio buttons. A B C D E
B (if selected) needs to activate a text field of 25 chars
E (if selected) needs to activate a text field of 10 chars

if user selects B, then user can type in "happy"; user then changes mind and selects D. "happy" is erased and the textfield is disabled. user then changes mind again and selects B and this time types in "not so happy"; then user changes mind selects E and types in "whatever" (B is blanked and disabled). then user selects A and hits submit. (B and E should be blanked and disabled... form returns value A as submited.

 cheap example of using one checkbox to toggle one textbox... blah!



<html><head><title>Toggle My Text Box</title>
<script language="JavaScript">

function textme () {
if(document.f1.mycheckbox.checked)
{
document.f1.textinput.disabled=false;
}
else
{
document.f1.textinput.disabled=true;
}
}
</script>

<form action="" method="" name="f1">
  <input type="text" disabled size="10" name="textinput">
  <input type="checkbox" onclick="textme()" name="mycheckbox" value="on" >
 <br>
 <input type="submit" value="Add">
  <input type="reset" value="Clear">
  </form>
</body></html>
__________________
In a world of give and take, take all you can and you die with nothing.&nbsp;&nbsp;Give all you can and you&nbsp;&nbsp;die with honor.
 
Old April 4th, 2005, 12:13 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

Hii Hatchingabrain !!
Hope this will help you

 <form name="myform">
<input type=text name="textbox" > <br>
<input type=radio name="rad_btn" value="A" onclick="setInput()">A <br>
<input type=radio name="rad_btn" value="B" onclick="setInput()">B <br>
<input type=radio name="rad_btn" value="C" onclick="setInput()">C <br>
<input type=radio name="rad_btn" value="D" onclick="setInput()">D <br>
<input type=radio name="rad_btn" value="E" onclick="setInput()">E <br>
</form>

<script>

// document.myform.rad_btn[0] checkbox A.
// document.myform.rad_btn[1] checkbox B.
// document.myform.rad_btn[2] checkbox C.
// document.myform.rad_btn[3] checkbox D.
// document.myform.rad_btn[4] checkbox E.

function setInput()
{



if(document.myform.rad_btn[1].checked)
{
document.myform.textbox.disabled=false
document.myform.textbox.size=25

}

if(document.myform.rad_btn[4].checked)
{
document.myform.textbox.disabled=false
document.myform.textbox.size=10
}


if(document.myform.rad_btn[2].checked)
{
document.myform.textbox.value=""
document.myform.textbox.disabled=true;

}


}

</script>

Cheers :)

vinod
 
Old April 4th, 2005, 07:13 AM
Authorized User
 
Join Date: Apr 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great... I would just need:
if(document.myform.rad_btn[/*BTN NUMBER*/].checked)
{
document.myform.textbox.value=""
document.myform.textbox.disabled=true;
}

for EACH of the non text radios....

Thanks :D





Similar Threads
Thread Thread Starter Forum Replies Last Post
Toggle active state of text area with radio button Hatchingabrain Javascript 2 April 4th, 2005 04:03 AM
Toggle Button Problem cco2000 Access 0 March 23rd, 2004 09:26 PM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM
display value of selected radio in the textbox hosefo81 Javascript How-To 1 February 1st, 2004 07:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.