Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Enable multiple text fields with checkbox

    Hello.
    I have a check box and a text field.
    When the page is loaded, the text field is disabled, but then when a user clicks the check box, the text field is enabled.

    I used this code from a previous post by cheesebag to do that:

    Code:
    <form name="form">
    <input name="enableDisableTask" type="checkbox" onclick="email.disabled=!this.checked">
    Email <input name="email" type="text" value="" disabled="disabled">
    </form>
    However, I want to be able to add another text field, and have that new one ALSO be enabled when the user checks the check box. Is there an easy way to do this? Thanks.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    u can do this, trick is to make sure the name of the text field is the same name as in the onclick
    Code:
    <form name="form">
    <input name="enableDisableTask" type="checkbox" onclick="email.disabled=!this.checked">
    Email <input name="email" type="text" value="" disabled="disabled">
    <input name="enableDisableTask2" type="checkbox" onclick="newfield.disabled=!this.checked">
    New Field <input name="newfield" type="text" value="" disabled="disabled">
    </form>

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think I didn't phrase my question correctly. My mistake.
    I need the one check box to control the enable/disable function for both text fields. In other words, how can I accomplish enabling and disabling two text fields using only one check box. Does that make sense?
    Thank you for your qucik reply though.

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    ahh okay then do this, trick still is to be sure name matches the onclick in the checkbox input
    Code:
    <form name="form">
    <input name="enableDisableTask" type="checkbox" onclick="(email.disabled=!this.checked)&(newfield.disabled=!this.checked)">
    Email <input name="email" type="text" value="" disabled="disabled">
    New Field <input name="newfield" type="text" value="" disabled="disabled">
    </form>
    sorry for the mixup

  • #5
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I KNEW it had to be something as simple as that. THANKS A LOT!
    I was searching for about an hour on other message boards and tutorial sites, and they ALL over complicated what I wanted to do. Thanks again.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    lol sometimes its best to keep things simple


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •