www.webdeveloper.com
Results 1 to 3 of 3

Thread: Need help with showing/hiding div depending on checkbox but not using onclick

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    4

    Need help with showing/hiding div depending on checkbox but not using onclick

    Hi guys, I have a php form (with javascript), at the moment I have hidden divs that appear when an earlier checkbox is ticked (checked). However, I'm now wanting to add some code earlier that will auto tick some of the checkboxes, I am still wanting the same hidden divs to appear but because the checkboxes aren't being physically clicked it's not working, does anyone know a good way to make the divs still appear if the checkboxes are selected?

    Any help would be much appreciated.
    thanks

    my current code:

    in head:
    Code:
    <script type="text/javascript"> 
    <!-- 
    function showMe (it, box) { 
    var vis = (box.checked) ? "block" : "none"; 
    document.getElementById(it).style.display = vis;
    } 
    //--> 
    </script>

    in body:
    HTML Code:
    <input type="checkbox" name="UserFPArea1" value="FPA-South" onClick="showMe('SouthFP', this)" /> Example Checkbox
    HTML Code:
    <div id="SouthFP" style="display:none">example hidden div</div>

  2. #2
    Join Date
    May 2003
    Posts
    599
    You might want to check the javascript forum...I think what you want to do is loop all the checkboxes on any input click, then based on conditions, the dependent boxes get ticked automatically, and divs would be visible as needed....so effectively your still using the onClick().

    You could use the same function on page load if needed.
    We do precision guesswork

  3. #3
    Join Date
    Jul 2012
    Location
    Vancouver
    Posts
    61
    Change the value of the checkbox, then follow up with .onChange();

    obviously you need a handler for the onchange - otherwise it won't do anything
    Last edited by mistin.ca; 10-18-2012 at 05:16 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles