SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: adding form elements using checkbox

  1. #1
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    adding form elements using checkbox

    sounds pretty simple:
    I have a checkout form with the user providing his (billing) address.
    Then by clicking a checkbox, additional fields should open for providing a shipping address.
    I don't want to have both fieldsets open right from the start but the second toggling when required, since i think it's an easier checkout process asking the user something like "ship to an other address" than showing a bunch of possibly unnecessary fields.

    Long story short, since i have not really a clue of JS, JQuery etc. is there a (more or less) 'ready-to-go' script i could use?
    I do it in PHP right now but think it might be (again) more userfriendly not to go serverside right away.
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  2. #2
    Grüße aus'm Pott
    SitePoint Award Recipient Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    2,489
    Mentioned
    40 Post(s)
    Tagged
    3 Thread(s)
    Hi there,
    Shouldn't be too difficult. Something like this:

    HTML Code:
    <input type="checkbox" name="mycheckbox" id="mycheckbox" value="0" />
    <div id="mycheckboxdiv" style="display:none">
        This content should appear when the checkbox is checked
    </div>
    
    <script type="text/javascript">
    $('#mycheckbox').change(function() {
        $('#mycheckboxdiv').toggle();
    });
    </script>
    I got this from here: http://stackoverflow.com/questions/7...ked-expand-div
    How well do you know your JavaScript from your jQuery?
    Check out SitePoint's latest JavaScript challenge


    My blog

Bookmarks

Posting Permissions

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