Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 2nd, 2005, 11:17 PM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
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.
Reply With Quote
  #2 (permalink)  
Old April 4th, 2005, 12:13 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Reply With Quote
  #3 (permalink)  
Old April 4th, 2005, 07:13 AM
Authorized User
 
Join Date: Apr 2005
Location: , , USA.
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:04 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.