www.webdeveloper.com
Results 1 to 4 of 4

Thread: Passing A Value Through A Dropdown Menu

  1. #1
    Join Date
    Apr 2010
    Posts
    23

    Passing A Value Through A Dropdown Menu

    I am using a system called CMS Made Simple which has a quotes feature. This will generate a quote randomly from a MySQL database. To refer to this quote feature you have to use the {quote} tag which has a few parameters.

    The parameter I am interested in is {quote group=""} because I want my users to be able to see a random quote from a group that they select through a dropdown list. The guys over on the CMS Made Simple forum were very helpful and came up this code:

    Head section:

    Code:
    <script type="text/javascript" src="path/to/jquery.js"></script>
    {literal}
    <script type="text/javascript">
    $(document).ready(function(){
    $('#grp1').hide();
    $('#grp2').hide();
    $('#grp3').hide();
    $("#thechoices").change(function(){
    $("#" + this.value).show().siblings().hide();
    });
    
    $("#thechoices").change();
    });
    </script>
    {/literal}
    Code:
    <select id="thechoices">
    <option value="grp1">Group 1</option>
    <option value="grp2">Group 2</option>
    <option value="grp3">Group 3</option>
    </select>
    
    <!-- the DIVs -->
    <div id="quotes">
    <div id="grp1">{quotes group="grp1"}</div>
    <div id="grp2">{quotes group="grp2"}</div>
    <div id="grp3">{quotes group="grp3"}</div>
    </div>
    Which functions just fine. However the problem with this code is that I plan to have 65 different groups for the user to select from. When I have tried to do this the webpage has become very slow. I presume this is from loading 65 random quotes from a MySQL database in case the user selects the div - a very slow method which needs to be put on the backburner!

    Essentially I would like only the first Div to load with the webpage and the others to load when they are selected in the dropdown list.

    I realise other threads exist which are similar to this but they do not pass parameters in the same way and I also saw someone say to start your own thread rather than hijacking someone elses!

    Please note that my experience with Javascript is rather limited when replying.

    Thank you for any help.

  2. #2
    Join Date
    Apr 2010
    Posts
    23
    I can't seem to edit the post?

    Anyway, yes I realise that I have left the src as 'src="path/to/jquery.js' - on my webpage it is assigned correctly!

  3. #3
    Join Date
    Sep 2009
    Posts
    27
    Change /path/to/ to the actual path to the script location.

    Ajax might be what you need (to load div content as selected). Example introduction to ajax: http://daniel.lorch.cc/docs/ajax_simple/

    Or consider asking mySQL to do the random sampling, something like (from memory) WHERE ... ORDER BY RAND() LIMIT 5
    Last edited by kina; 04-19-2010 at 07:42 PM.

  4. #4
    Join Date
    Apr 2010
    Posts
    23
    Pointing me in the direction of Ajax was very helpful, thanks.

    I now have a setup that loads seperate files when selected:

    Code:
    <form>
    <select id="ajaxmenu" size="1" onChange="ajaxcombo('ajaxmenu', 'contentarea')">
    <option value="">Select A file to load</option>
    <option value="index.htm">Page 1</option>
    <option value="ajaxfiles/external.htm">Page 2</option>
    <option value="ajaxfiles/external2.htm">Page 3</option>
    </select>
    </form>
    
    <div id="contentarea"></div>
    But really I need it to change the value of the contents of 'contentarea' otherwise the system won't work.

    Any ideas?

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