...

View Full Version : the GET value is not passing to populate Sub-Records



DataTalk
11-30-2010, 05:04 PM
<!-- *** 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'];
}
}
?>

Old Pedant
12-01-2010, 02:05 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum