parse value from 1 dropdown list to another list onChange event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryangsh
    New Member
    • Jun 2010
    • 2

    parse value from 1 dropdown list to another list onChange event

    hi guys, need your expertise...

    I'm trying to create a list for group of associates by group and when a group is selected the associates assigned to that group will appear in a list

    sample
    Code:
     
    <select name="groupName">
    <?php $rs_groupSearch="SELECT * FROM tblGroup";
    $groupCount=mysql_num_rows($rs_groupSearch);
    if($groupCount>0){
       while($Groups=mysql_fetch_array($rs_groupSearch)){
    ?>
        <option><?php echo $Groups['GroupName']; ?></option>
    <?php } else { ?>
        <option>No Groups in List</option>
    <?php } ?>
    </select>
    when user select a group then it will display the names of the selected group members (the above code works fine)

    Code:
     
    <select name="groupMembers" size="4">
    <?php $rs_groupMemberSearch="SELECT * FROM tblGroupMembers 
    WHERE GroupName='$groupName'"; //This is where i'm stuck 
    //$groupName is the name of list box above i don't know 
    //how to parse the value from that list to this sql
    $groupMemberCount=mysql_num_rows($rs_groupMemberSearch);
    if($groupMemberCount>0){
       while($GroupMembers=mysql_fetch_array($rs_groupMemberSearch)){
    ?>
        <option><?php echo $Groups['MemberName']; ?></option>
    <?php } else { ?>
        <option>No Members in List</option>
    <?php } ?>
    </select>
    Note: I would like to do this without hitting the submit button just like how other website do their country,state drop down list. I don't mind having the list to submit itself

    i have tried some examples from the net but its not working
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Hey Ryangsh,

    Lists don't submit themselves, lists can call javascript functions with their event handlers (onclick, onchange, onblur, so on)

    So in one of these, you're list can submit the form, and therefore the list's selected value to a (php) script on the server.

    The server can then know what is selected and reply back with a /new/ page (or the same page with added content), which of course this would be the name of the associates in that selected group.

    This, as you may have already guessed, does a call to the server and refreshes the page, which is something you like to prevent I assume.

    So the only technology that I know that can do this without refresh is called AJAX, or shortly Asynchronous Javascript.

    AJAX is just fancy Javascript code that does a call to the server behind the scenes and can parse the data returned from the server. Of course the "thing" returned can't be another page, your php should as an example, return a list of names with commas in between them and NOTHING more.

    This way, Javascript code can then parse the names and put them in any element on your HTML page, All in a blink of an eye!

    Learn Javascrip/AJAX and forward any questions you have to the appropriate forum, If you get stuck in the PHP code, feel free to come back here.

    Cheers,




    Dan

    Comment

    Working...