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 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts

    when selection is made checkbox is enabled. otherwise checkbox is disabled.

    alright guys how is everbody today?

    I have a situation where I need some help.

    I have a combo box and a check box.

    in the code below. when selection 3 is made I need the checkbox to enable. otherwise check box is disabled.

    Code:
     <select name="menu" size="3">
            <option value="1">selection 1</option>
            <option value="2">selection 2</option>
            <option value="3">selection 3</option>
            <option value="3">selection 4</option>
            <option value="3">selection 5</option>
        </select>
        
        <input name="" type="checkbox" value="" />

    thanks for the help
    Last edited by Mthor; 09-24-2008 at 09:45 PM.

  • #2
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    Code:
    <select name="menu" size="3" onchange="check();">
            <option value="1">selection 1</option>
            <option value="2">selection 2</option>
            <option value="3">selection 3</option>
            <option value="3">selection 4</option>
            <option value="3">selection 5</option>
        </select>
        
        <input name="yourcheckbox" type="checkbox" value="" disabled="true"/>
    Code:
    function check(){
    if (document.formname.menu.value == '3'){ document.formname.yourcheckbox.disabled=false;}else{document.formname.yourcheckbox.disabled=true;}
    
    }
    maybe there's a better way, that just came to me first

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts
    i tried that. but it didn't work.

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <script>
    	function check(){
    if (document.formname.menu.value == '3'){ document.formname.yourcheckbox.disabled=false;}else{document.formname.yourcheckbox.disabled=true;}
    
    }
    </script>
    </head>
    
    <body>
        <select name="menu" size="3" onchange="check();">
            <option value="1">selection 1</option>
            <option value="2">selection 2</option>
            <option value="3">selection 3</option>
            <option value="3">selection 4</option>
            <option value="3">selection 5</option>
        </select>
        
        <input name="yourcheckbox" type="checkbox" value="" disabled="true"/>
    </body>
    </html>

  • #4
    Regular Coder ohgod's Avatar
    Join Date
    Jun 2008
    Location
    Ohio
    Posts
    579
    Thanks
    6
    Thanked 69 Times in 69 Posts
    yeah.... you don't have a form. i thought you posted incomplete code.

    anyway, you need to build it out like a form, with <form> tags and all that. looks it up on w3schools if you're unfamiliar with it.

  • Users who have thanked ohgod for this post:

    Mthor (09-25-2008)

  • #5
    New Coder
    Join Date
    Sep 2008
    Posts
    37
    Thanks
    5
    Thanked 0 Times in 0 Posts
    OMG I cant believe I forgot that.


    thanks for all your help. it works great.


  •  

    Posting Permissions

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