Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
Like Tree1Likes
  • 1 Post By TheGAME1264

Thread: Dynamic Forms

  1. #1
    Senior Member medlington's Avatar
    Join Date
    Nov 2005
    Location
    Sheffield, UK
    Posts
    377
    Member #
    11968
    Liked
    4 times

    Dynamic Forms

    Hi,

    Im wanting to create a dynamic form where the user selects an option from a dropdown menu item and then depending upon which item they select a different set of new options / form elements will appear below without submitting the form.

    eg,

    if the user selected 'house' from the dropdown then several radio buttons would appear underneath with the options of 'door', 'window', 'roof' etc and if they had selected 'car' from the initial dropdown the options that would appear would be 'wheel', 'brake' etc.

    Im guessing I need to create all the possible form elements in separate divs that are hidden and then have some script make them appear depending upon which is selected.

    So can anyone point me in the right direction for a tutorial on this?

    Thanks

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    That's done using Javascript and the onchange event handler. jQuery also has a change event handler for this.

    JavaScript - Changing Drop Down Lists <-- here's a Javascript example.
    So You Need To Fill a Dropdown Dynamically | CSS-Tricks <-- and here's jQuery.
    medlington likes this.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Senior Member Webzarus's Avatar
    Join Date
    May 2011
    Location
    South Carolina Coast
    Posts
    3,322
    Member #
    27709
    Liked
    770 times
    there's also the OLD SCHOOL way... using Session Variables.. refreshing the page and displaying more info based on user selection.

    Using CSS and a decent host... the page refresh shouldn't even be noticable

  5. #4
    Senior Member medlington's Avatar
    Join Date
    Nov 2005
    Location
    Sheffield, UK
    Posts
    377
    Member #
    11968
    Liked
    4 times
    Ive managed to get a little stuck with this now and Im sure it should be easy.

    Im trying to get it so that I select from a dropdown and then that limits what is in the next dropdown so first I select a room and then I only want tables within that room to be displayed in the next dropdown. Ideally Id like it so that all the possible options were available in the next dropdown but only the relevant ones show so that I can process the info more easily in the next script.

    Heres what I have so far but it doesnt seem to do anything. Is it possible to hide more than one element at the same time with the same ID?

    This is my Java:
    Code:
    <script type='text/javascript'>
    
    function show(obj, obj2, obj3) {
    var el = document.getElementById(obj);
    var el2 = document.getElementById(obj2);
    var el2 = document.getElementById(obj3);
    el.style.display = "block";
    el2.style.display = "none";
    el3.style.display = "none";
    }
    
    </script>
    and this is my HTML
    Code:
    <form action="" method="POST">
    
        <select name="room">
            <option value="" selected="selected"></option>
          <option value="room1" onchange="show('hide1','hide2','hide3')" >tab 1 + 2</option>
          <option value="room2" onchange="show('hide2','hide1','hide3')" >tab 3 + 4 + 5</option>
          <option value="room3" onchange="show('hide3','hide1','hide2')" >tab 6</option>
        </select>
        
        <select name="table">
            <option value="" selected="selected"></option>
          <option value="tab1" id="hide1">tab1</option>
          <option value="tab2" id="hide1">tab2</option>
          <option value="tab3" id="hide2">tab3</option>
          <option value="tab4" id="hide2">tab4</option>
          <option value="tab5" id="hide2">tab5</option>
          <option value="tab6" id="hide3">tab6</option>
        
        </select>
    </form>
    But as you can see it doesnt do anything: Untitled Document

    So where am I going wrong? is it that you cant hide <options> or because I have multiple instances of the same ID? nothing is showing in Firebug.

    Can anyone think of a better way to achieve this?

    Thanks

  6. #5
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    You'll probably find what you're trying to do a lot easier if you use jQuery and data.

    jQuery.data() | jQuery API Documentation

    Instead of assigning IDs, you could assign data-showlevel="hide1" and then adjust from there.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  7. #6
    Junior Member
    Join Date
    Oct 2013
    Posts
    3
    Member #
    37478
    javascript is also use for apply validation and secure the web form. Ajax tool is very powerfull use in web page we can apply each and every validation on our web page.

  8. #7
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,485
    Member #
    425
    Liked
    2783 times
    When the hell did Javascript have anything to do with securing a web form? What are you talking about (besides suspected post count inflation)?
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:18 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com