Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Nov 2010
    Location
    Oregon
    Posts
    243
    Thanks
    23
    Thanked 10 Times in 10 Posts

    the GET value is not passing to populate Sub-Records

    <!-- *** THIS SCRIPT IS NOT WORKING "WHAT AM I MISSING???" *** -->
    <!-- *** THE FIRST DROPDOWN GETS THE DATA FROM (db)qw_groups BUT DOES NOT "@GET" and pass the value to qw_groupitems *** -->
    <!-- *** first dropdown value=$group[id] *** -->
    <!-- *** Then second dropdown should populate with: $q = mysql_query("SELECT * FROM qw_groupitems WHERE GroupId ='$groups'"); *** -->
    <!-- *** the .php code listed below, the page is: csa_ajax.php *** -->



    <!-- *** HERE IS THE COMPLETE CODE *** -->

    <script type="text/javascript">
    var request = false;
    if (!request && typeof XMLHttpRequest != 'undefined') {
    request = new XMLHttpRequest();
    }

    function fillSelect(groups) {
    var url = "csa_ajax.php?groups=" + escape(groups);
    request.open("GET", url, true);
    request.onreadystatechange = go;
    request.send(null);
    }

    function go() {
    if (request.readyState == 4) {
    if (request.status == 200) {
    var response = request.responseText;
    var list=document.getElementById("groupitems");
    var groupitems=response.split('|');
    for (i=1; i<groupitems.length; i++) {
    var x=document.createElement('option');
    var y=document.createTextNode(groupitems[i]);
    x.appendChild(y);
    list.appendChild(x);
    }
    }
    }
    }

    function initCs() {
    var groups=document.getElementById('groups');
    groups.onchange=function() {
    if(this.value!="") {
    var list=document.getElementById("groupitems");
    while (list.childNodes[0]) {
    list.removeChild(list.childNodes[0])
    }
    fillSelect(this.value);
    }
    }
    fillSelect(groups.value);
    }
    window.onload=initCs;
    </script>


    <form method="post" action="#">
    <p><label>groups: <select id="groups" name="groups">
    <?php
    require_once("includes/connect.php");
    $mysql = mysql_query("SELECT * FROM qw_groups");
    while($group=mysql_fetch_assoc($mysql)){
    echo "<option value='$group[id]'>$group[GroupName]</option>";
    }
    echo "</select>";
    ?>
    </label>
    <?php
    echo "<label>groupitems: <select id='groupitems' name='groupitems'>";
    echo "</select>";
    ?>
    </label></p>
    </form>



    <!-- *** HERE IS THE PHP PAGE csa_ajax.php ***-->

    <?php
    require_once("includes/connect.php");
    $groups=@$_GET['groups'];
    $q = mysql_query("SELECT * FROM qw_groupitems WHERE GroupId ='$groups'");
    while ($r = mysql_fetch_assoc($q)){
    echo "|".$r['GroupId'];
    }
    }
    ?>
    Last edited by DataTalk; 11-30-2010 at 04:36 PM.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,324 Times in 4,290 Posts
    This is a duplicate (much duplicated) post of a couple of threads in the main JS forum. Let's leave it in the JS forum.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •