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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    displaying checkbox on the screen

    Hi friends,
    I have a dropdown menu,when i select one item from the dropdown menu,i want a checkbox to be created on the screen.How do i achieve this?

    Thank You
    Madhusudan

  • #2
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Use document.createElement() and element.appendChild() to manipulate the DOM tree...

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,990
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    No need to "manipulate the DOM tree". Use this:-


    Code:
    <select id = "mysel" onchange = "showbox()">
    <option value = 0>Select an option....</option>
    <option value = 1>Option One</option>
    <option value = 2>Option Two</option>
    <option value = 3>Option Three</option>
    </select>
    
    <div id = "boxcontainer" style="display:none">
    Check this box <input type = "checkbox" id = "chk1">
    </div>
    
    <script type = "text/javascript">
    
    function showbox() {
    document.getElementById("boxcontainer").style.display="none";  // hide the checkbox
    document.getElementById("chk1").checked = false;   // uncheck if a different option is chosen
    var val = document.getElementById("mysel").selectedIndex;
    if (val == 3) {  // or whatever option applies
    document.getElementById("boxcontainer").style.display="inline";  // show the checkbox
    }
    
    }
    </script>
    Quizmaster: What is a chaffinch?
    Contestant: It is a measurement
    Last edited by Philip M; 12-31-2011 at 03:47 PM.

    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.


  •  

    Posting Permissions

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