SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to create linked listboxes using PHP ?

    Hi ppl, like to know how can i create such a combo box in my code ? For the uninitiaited, well lets say i got 2 listboxes, listBox1,listBox2 and listBox3...upon entry, only listBox1 has values of different categories of data, upon selection of a value from listBox1, listBox2 will populate the next set of data from the database and then once a value in listbox2 is selected, the user can select thefinal value from the 3rd listbox.

    Not too sure if i am on the right track, listBox1 should reference a Category tbl, listBox2 reference a Sub_Category tbl which has a Catogry foreign key, and lastly listBox3 should referece a specific product that was based on a category and sub cateogry foreign key

    many thanks for the advice in advance !!

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    More of a javascript question really as you would use onChange action....
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Alright, so how do i proceed ?

    Quote Originally Posted by spikeZ
    More of a javascript question really as you would use onChange action....
    alright, if its a javascript based solution, but does Javascript support database access ? i'm using a mySQL database

  4. #4
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    generate listbox from php and use javascript for change page location

  5. #5
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    f.e.

    <script>
    function do_relocation( select ){
    document.location = select.value;
    }
    </script>
    <select name='test' class='test' onchange='do_relocation(this)'>
    <?php
    $result = mysql_query( "select...." );
    while ( $row = mysql_fetch_array( $result ) ){
    echo "<option value='".$row['url'].'">$row['label_name']."</option>\n";
    }
    ?>
    </select>

  6. #6
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wats do_relocation ?

    Quote Originally Posted by St.
    f.e.

    <script>
    function do_relocation( select ){
    document.location = select.value;
    }
    </script>
    <select name='test' class='test' onchange='do_relocation(this)'>
    <?php
    $result = mysql_query( "select...." );
    while ( $row = mysql_fetch_array( $result ) ){
    echo "<option value='".$row['url'].'">$row['label_name']."</option>\n";
    }
    ?>
    </select>
    Hi ST, thanks for your help, but may i noe the purpose of the do_relocation ? sorry,but i don't really know whats the actionperform method is supposed to do ...

  7. #7
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do_relocation is javascript function. it calling when listbox change state.

    you can do it like this
    <select name='test' class='test' onchange='document.location=this.value'>
    without writing javascript

    or you can do it like this
    <script>
    function change_location( link_url ){
    document.location=link_url;
    }
    </script>
    <select name..... onchange='change_location( this.value )'>

    or you can do it like i showed at my last message

    study javascript for understand this

  8. #8
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Okay i get it but ..

    Quote Originally Posted by St.
    do_relocation is javascript function. it calling when listbox change state.

    you can do it like this
    <select name='test' class='test' onchange='document.location=this.value'>
    without writing javascript

    or you can do it like this
    <script>
    function change_location( link_url ){
    document.location=link_url;
    }
    </script>
    <select name..... onchange='change_location( this.value )'>

    or you can do it like i showed at my last message

    study javascript for understand this
    alright i understand the coding now, but then what happens to the 2nd listBoxs values ? will it not get dynamically polulated ? cause i working with 3 listboxes where the 3rd box's values depends on 2nd box's values depends on the 1st

  9. #9
    SitePoint Enthusiast
    Join Date
    Oct 2004
    Location
    Singapore
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by St.
    do_relocation is javascript function. it calling when listbox change state.

    you can do it like this
    <select name='test' class='test' onchange='document.location=this.value'>
    without writing javascript

    or you can do it like this
    <script>
    function change_location( link_url ){
    document.location=link_url;
    }
    </script>
    <select name..... onchange='change_location( this.value )'>

    or you can do it like i showed at my last message

    study javascript for understand this

    ermm just asking ...your select tag onchage= "change_location(this.value)">

    thats a method call to a javascript right ? it doesn't work or did u just write in a pseuducode format ?

  10. #10
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not. it's not pseudocode, may be it's mistake 8) i wished show mechanism.

    if you have depends with your listboxes, you must picture their logic for take a help

  11. #11
    Non-Member St.'s Avatar
    Join Date
    Nov 2004
    Location
    Cloud #9
    Posts
    119
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    by the way. are you thinked about search robots?
    if navigation on your site will work throw listboxes without alternative methods,
    you'll have problem with indexing your site in search machines.


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
  •