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
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    If checkbox is checked show input field

    I've not really an idea how to do this. I know how to do it in PHP, but I need it dynamic

    <input type="checkbox" name="facebook" value="1" />
    if($_POST['facebook'] == 1)
    echo "<input type='text' name='facebook_url' />";

    Could someone tell me how I should do this.

    Thanks.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    not sure what it would look like in php, but in js you could do this:
    Code:
    <body>
    <input type="checkbox" name="facebook" value="1" onclick="showBox(this)"/>
    <input type='text' name='facebook_url' id='fb' style="display:none"/>
    <script type="text/javascript"> 
    function showBox(elem){
    document.getElementById("fb").style.display=elem.checked?"block":"none";
    }
    </script>

  • #3
    Regular Coder
    Join Date
    Sep 2011
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hmm thank you, I am not good with JS but that isn't a hard solution, I don't see why I didn't think of that. Thank you!


  •  

    Posting Permissions

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