PHP / Javascript menu list population

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bigfella

    PHP / Javascript menu list population

    Hello Folks,

    I would like a web page to have 2 menu lists

    The contents of the second menu list depending on the selection made in
    the first.

    The contents of the second would be populated from a database.

    I am fairly new to programming using PHP, Javascript and MySQL but I am
    sure what I am asking has been done before. Could someone please give
    me some pointers or direct me to a tutorial.

    Cheers
    Darren

  • Colin McKinnon

    #2
    Re: PHP / Javascript menu list population

    bigfella wrote:
    [color=blue]
    > Hello Folks,
    >
    > I would like a web page to have 2 menu lists
    >
    > The contents of the second menu list depending on the selection made in
    > the first.
    >
    > The contents of the second would be populated from a database.
    >
    > I am fairly new to programming using PHP, Javascript and MySQL but I am
    > sure what I am asking has been done before. Could someone please give
    > me some pointers or direct me to a tutorial.
    >[/color]

    This *seriously* is not trivial. Try reading up on ajax and javascript RPC.

    As an alternative way to solve the problem...
    Way back when....Netscap e used to render select/optgroup/...optgroup/option
    as a cascaded menu but none of the current browsers do that - I guess you
    could use PHP Layers menu to acheive the result.

    C.

    Comment

    • Chung Leong

      #3
      Re: PHP / Javascript menu list population


      bigfella wrote:[color=blue]
      > Hello Folks,
      >
      > I would like a web page to have 2 menu lists
      >
      > The contents of the second menu list depending on the selection made in
      > the first.[/color]

      The easiest way to do this is to create all the secondary menus and
      show/hide them depending on the selection of the primary menu.

      Example:

      <script language="Javas cript">

      var cur_val = '0';

      function ShowSecond(sel) {
      var new_val = '0';
      if(sel.selected Index != -1) {
      new_val = sel.options[sel.selectedInd ex].value;
      }
      document.getEle mentById('sel_' + cur_val).style. display = 'none';
      document.getEle mentById('sel_' + new_val).style. display = 'inline';
      cur_val = new_val;
      }

      </script>
      <select onchange="ShowS econd(this)">
      <option value="0" selected>- Select -</option>
      <option value="1">One</option>
      <option value="2">Two</option>
      <option value="3">Three </option>
      <option value="4">Four</option>
      </select>
      <select id="sel_1" style="display: none">
      <option>List One</option>
      </select><select id="sel_2" style="display: none">
      <option>List Two</option>
      </select><select id="sel_3" style="display: none">
      <option>List Three</option>
      </select><select id="sel_4" style="display: none">
      <option>List Four</option>
      </select><select id="sel_0" disabled>
      <option>Placeho lder</option>
      </select>

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: PHP / Javascript menu list population

        bigfella wrote:[color=blue]
        > Hello Folks,
        >
        > I would like a web page to have 2 menu lists
        >
        > The contents of the second menu list depending on the selection made in
        > the first.
        >
        > The contents of the second would be populated from a database.[/color]

        The simple solution is to hack other source codes and google it
        <http://home.att.net/~codeLibrary/HTML/dropdown.htm> Possibly the
        easiest way to do is to generate the JavaScript code using PHP (the
        multi-dimensional array) as in the above link. But, if there is lot of
        data, the browser may run out of memory. In that case, as Colin
        suggested AJAX techniques might help.

        --
        <?php echo 'Just another PHP saint'; ?>
        Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

        Comment

        • jkimball4@gmail.com

          #5
          Re: PHP / Javascript menu list population


          bigfella wrote:[color=blue]
          > Hello Folks,
          >
          > I would like a web page to have 2 menu lists
          >
          > The contents of the second menu list depending on the selection made in
          > the first.
          >
          > The contents of the second would be populated from a database.
          >
          > I am fairly new to programming using PHP, Javascript and MySQL but I am
          > sure what I am asking has been done before. Could someone please give
          > me some pointers or direct me to a tutorial.
          >
          > Cheers
          > Darren[/color]

          Or better yet, do a menu using lists and css. This requires no
          javascript, just some css tinkering. Check out Listamatic2 at
          maxdesign. I think any solution in there will be easily customizable
          to your situation. Then all you have worry about is the backend PHP.

          Comment

          • R. Rajesh Jeba Anbiah

            #6
            Re: PHP / Javascript menu list population

            jkimball4@gmail .com wrote:[color=blue]
            > bigfella wrote:[/color]
            <snip>[color=blue][color=green]
            > > The contents of the second menu list depending on the selection made in
            > > the first.
            > >
            > > The contents of the second would be populated from a database.[/color][/color]
            <snip>[color=blue]
            > Or better yet, do a menu using lists and css. This requires no
            > javascript, just some css tinkering. Check out Listamatic2 at
            > maxdesign. I think any solution in there will be easily customizable
            > to your situation. Then all you have worry about is the backend PHP.[/color]

            I suppose, the OP wants dropdown list. By any chance, is it
            possible to do with CSS hacks?

            --
            <?php echo 'Just another PHP saint'; ?>
            Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

            Comment

            Working...