SemperFiWS
asked on
AJAX 3 Level Selections
I am attempting to create a 3 level drop down using PHP + MySQL + AJAX
The majority of it I have working as I want.
There are three things I require a bit of help with to get this completed.
#1 - Relationships
I need the third selection to relate to both the first and second selection.
Currently it only relates to the second.
#2 - Default Values
Rather than blank or 'Please Selects' I would like each of the 3 levels to start with a default value
e.g.
First level, first value 'selected'
Second Level, first value based off First Level selected
Third Level, first value based off First Level and Secon Level selected
#3 - Retained Values
When the search is run, I would like it if the 3 selections previously made are retained.
Below is the code I am currently using.
Any help that can be provided with this would be greatly appreciated.
The majority of it I have working as I want.
There are three things I require a bit of help with to get this completed.
#1 - Relationships
I need the third selection to relate to both the first and second selection.
Currently it only relates to the second.
#2 - Default Values
Rather than blank or 'Please Selects' I would like each of the 3 levels to start with a default value
e.g.
First level, first value 'selected'
Second Level, first value based off First Level selected
Third Level, first value based off First Level and Secon Level selected
#3 - Retained Values
When the search is run, I would like it if the 3 selections previously made are retained.
Below is the code I am currently using.
Any help that can be provided with this would be greatly appreciated.
---------------------
Start 'ajaxMySQL.php'
---------------------
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
echo "<select name='special_date' onChange=\"dochange('special_name', this.value)\">\n";
echo "<option value='0'>Please Select</option>\n";
$val2=$val;
//$val = substr($val,0,2);
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$val' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
} else if ($data=='special_name') {
echo "<select name='special_name' >\n";
echo "<option value='0'>Please Select</option>\n";
$val2=$val;
//$val = substr($val,0,4);
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_date = '$val2' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
}
echo "</select>\n";
?>
---------------------
End 'ajaxMySQL.php'
---------------------
And velow is purely a snippet of the code involved in a template file...
<div align="center" style="margin-bottom: 10px;">
<form name=sel>
{TOP_LEVEL_LABEL} <font id=special_type></font><br>
{THIRD_LEVEL_LABEL} <font id=special_date><select><option value='0'>Please Make Initial Selection</option></select></font><br>
{SECOND_LEVEL_LABEL} <font id=special_name><select><option value='0'>Please Make Initial Selection</option></select></font><br><br>
<input type="hidden" name="searchStr" value="" />
<input type="hidden" name="_a" value="viewCat" />
<input type="submit" value='Submit the form data'>
</div>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "ajaxMysql.php?data="+src+"&val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
req.send(null);
}
window.onLoad=dochange('special_type', -1);
</script>
ASKER
Thanks for the comment, but unfortunately that wont work.
Because of how things currently are, it would result in a query like:
SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = 2008-10-17 AND special_date = '2008-10-17' ORDER BY special_name ASC;
This happens because of how $val and $val2 are currently set.
i.e.
They are both from the second selection.
If there was a way of retaining and/or referencing the first selection, that would be great.
Because of how things currently are, it would result in a query like:
SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = 2008-10-17 AND special_date = '2008-10-17' ORDER BY special_name ASC;
This happens because of how $val and $val2 are currently set.
i.e.
They are both from the second selection.
If there was a way of retaining and/or referencing the first selection, that would be great.
ASKER
Ok, I have made some changes so the default selections are in place, so requirement #2 is now fully covered.
To get this finished up, all I basically need is:
- selections to be retained when the form is submitted.
- the last selection to run the query based off both the first and second selections.
What do I need to do to achieve these two final requirements?
To get this finished up, all I basically need is:
- selections to be retained when the form is submitted.
- the last selection to run the query based off both the first and second selections.
What do I need to do to achieve these two final requirements?
You could always collect $_POST values from each selection
http://us.php.net/manual/en/reserved.variables.post.php
http://us.php.net/manual/en/reserved.variables.post.php
// use these variables for referencing values in previous selections
$stype='';
$sdate='';
$sname='';
if (isset($_POST['special_type'])){$stype = $_POST['special_type'];}
if (isset($_POST['special_date'])){$sdate = $_POST['special_date'];}
if (isset($_POST['special_name'])){$sname = $_POST['special_name'];}
// Round 1 special_type == "" AND special_date == "" AND special_date == ""
// Round 2 special_type != "" AND special_date == "" AND special_date == ""
// Round 3 special_type != "" AND special_date != "" AND special_date != ""
// put code here for security against SQL attack
Just be careful you safe check the values so you won't be vulnerable to SQL Injection Attack.
Check your $_POST array
Check your $_POST array
$stype='';
$sdate='';
$sname='';
if (isset($_POST['special_type'])){$stype = $_POST['special_type'];}
if (isset($_POST['special_date'])){$sdate = $_POST['special_date'];}
if (isset($_POST['special_name'])){$sname = $_POST['special_name'];}
// Assumptions:
// Round 1 special_type == "" AND special_date == "" AND special_date == ""
// Round 2 special_type != "" AND special_date == "" AND special_date == ""
// Round 3 special_type != "" AND special_date != "" AND special_date != ""
// put code here for security against SQL Injection Attack
$stype='';
$sdate='';
$sname='';
if (isset($_POST['special_typ e'])){$sty pe = $_POST['special_type'];}
if (isset($_POST['special_dat e'])){$sda te = $_POST['special_date'];}
if (isset($_POST['special_nam e'])){$sna me = $_POST['special_name'];}
// Assumptions:
// Round 1 special_type == "" AND special_date == "" AND special_date == ""
// Round 2 special_type != "" AND special_date == "" AND special_date == ""
// Round 3 special_type != "" AND special_date != "" AND special_date == ""
// Round 4 special_type != "" AND special_date != "" AND special_date != ""
// put code here for security against SQL Injection Attack
$sdate='';
$sname='';
if (isset($_POST['special_typ
if (isset($_POST['special_dat
if (isset($_POST['special_nam
// Assumptions:
// Round 1 special_type == "" AND special_date == "" AND special_date == ""
// Round 2 special_type != "" AND special_date == "" AND special_date == ""
// Round 3 special_type != "" AND special_date != "" AND special_date == ""
// Round 4 special_type != "" AND special_date != "" AND special_date != ""
// put code here for security against SQL Injection Attack
ASKER
Thanks again for your efforts, very much appreciated.
I tried that and unfortunately there is no post array until the form gets submitted.
I was wondering if I could set a variable as part of the onChange
Or am I missing something really simple here?
I tried that and unfortunately there is no post array until the form gets submitted.
I was wondering if I could set a variable as part of the onChange
Or am I missing something really simple here?
You're welcome. Hopefully we'll find a solution.
Quick question:
Is there an order in which you make these selections.
E.G. Is there a sequence?
If so, what is the sequence of choices that are made.
Thanks,
NerdsOfTech
Quick question:
Is there an order in which you make these selections.
E.G. Is there a sequence?
If so, what is the sequence of choices that are made.
Thanks,
NerdsOfTech
ASKER
I sure hope so as this is very close to what I want and your help so far has been greatly appreciated.
The sequence goes something like...
- make first selection (radio buttons) (special_type)
- make second selection (drop down) (special_date, based off special_type selection)
- make third selection (drop down) (special_name, meant to be based off the two selections above)
Is that what you were after?
The sequence goes something like...
- make first selection (radio buttons) (special_type)
- make second selection (drop down) (special_date, based off special_type selection)
- make third selection (drop down) (special_name, meant to be based off the two selections above)
Is that what you were after?
Passing all of the selections through $_GET['val'] variable
Last stage is doChange 'completed' for all variable output
Check for any parse errors.
This should work
:)
=NerdsOfTech
Last stage is doChange 'completed' for all variable output
Check for any parse errors.
This should work
:)
=NerdsOfTech
---------------------
Start 'ajaxMySQL.php'
---------------------
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
$list = explode($val, ',');
$valSD = $list[0];
$valST = $list[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$val2=$val;
//$val = substr($val,0,4);
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else {
$list = explode($val, ',');
$valSN = $list[0];
$valSD = $list[1];
$valST = $list[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />'; // debug
?>
---------------------
End 'ajaxMySQL.php'
---------------------
And velow is purely a snippet of the code involved in a template file...
<div align="center" style="margin-bottom: 10px;">
<form name=sel>
{TOP_LEVEL_LABEL} <font id=special_type></font><br>
{THIRD_LEVEL_LABEL} <font id=special_date><select><option value='0'>Please Make Initial Selection</option></select></font><br>
{SECOND_LEVEL_LABEL} <font id=special_name><select><option value='0'>Please Make Initial Selection</option></select></font><br><br>
<input type="hidden" name="searchStr" value="" />
<input type="hidden" name="_a" value="viewCat" />
<input type="submit" value='Submit the form data'>
</div>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "ajaxMysql.php?val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
req.send(null);
}
window.onLoad=dochange(',,,'); // initialize form selection
</script>
Fixed 2 errors
---------------------
Start 'ajaxMySQL.php'
---------------------
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
$list = explode($val, ',');
$valSD = $list[0];
$valST = $list[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$val2=$val;
//$val = substr($val,0,4);
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else {
$list = explode($val, ',');
$valSN = $list[0];
$valSD = $list[1];
$valST = $list[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
---------------------
End 'ajaxMySQL.php'
---------------------
And velow is purely a snippet of the code involved in a template file...
<div align="center" style="margin-bottom: 10px;">
<form name=sel>
{TOP_LEVEL_LABEL} <font id=special_type></font><br>
{THIRD_LEVEL_LABEL} <font id=special_date><select><option value='0'>Please Make Initial Selection</option></select></font><br>
{SECOND_LEVEL_LABEL} <font id=special_name><select><option value='0'>Please Make Initial Selection</option></select></font><br><br>
<input type="hidden" name="searchStr" value="" />
<input type="hidden" name="_a" value="viewCat" />
<input type="submit" value='Submit the form data'>
</div>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "ajaxMysql.php?val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
req.send(null);
}
window.onLoad=dochange('special_type', -1); // initialize form selection
</script>
ASKER
I replaced the contents of 'ajaxMySQL.php' and unfortunately, it didn't work.
Where the debug gets echoed, only the second instance of "ST" had a actual value.
And the 3rd selection was unaffected by any of the previous choices.
Where the debug gets echoed, only the second instance of "ST" had a actual value.
And the 3rd selection was unaffected by any of the previous choices.
doh!
array explode ( string $delimiter , string $string [, int $limit ] )
array explode ( string $delimiter , string $string [, int $limit ] )
---------------------
Start 'ajaxMySQL.php'
---------------------
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
$list = explode(',', $val);
$valSD = $list[0];
$valST = $list[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else {
$list = explode(',', $val);
$valSN = $list[0];
$valSD = $list[1];
$valST = $list[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
---------------------
End 'ajaxMySQL.php'
---------------------
And velow is purely a snippet of the code involved in a template file...
<div align="center" style="margin-bottom: 10px;">
<form name=sel>
{TOP_LEVEL_LABEL} <font id=special_type></font><br>
{THIRD_LEVEL_LABEL} <font id=special_date><select><option value='0'>Please Make Initial Selection</option></select></font><br>
{SECOND_LEVEL_LABEL} <font id=special_name><select><option value='0'>Please Make Initial Selection</option></select></font><br><br>
<input type="hidden" name="searchStr" value="" />
<input type="hidden" name="_a" value="viewCat" />
<input type="submit" value='Submit the form data'>
</div>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "ajaxMysql.php?val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
req.send(null);
}
window.onLoad=dochange('special_type', -1); // initialize form selection
</script>
I reversed the explode statement around accidentally
Now you should get results with no errors. Let me know.
Now you should get results with no errors. Let me know.
ASKER
The second selection still has no effect on the 3rd selection values.
ASKER
Any further ideas on this one?
Are you getting values from the debug now? Let me know.
ASKER
No, only the first value gets retained in the debug.
I am guessing that this may have something to do with this:
req.open("GET", "ajaxMysql.php?val="+val);
in the javascript itself.
I am guessing that this may have something to do with this:
req.open("GET", "ajaxMysql.php?val="+val);
in the javascript itself.
You're right
---------------------
Start 'ajaxMySQL.php'
---------------------
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
print "Val: $val"; // debug val
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
$list = explode(',', $val);
$valSD = $list[0];
$valST = $list[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else {
$list = explode(',', $val);
$valSN = $list[0];
$valSD = $list[1];
$valST = $list[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
---------------------
End 'ajaxMySQL.php'
---------------------
And velow is purely a snippet of the code involved in a template file...
<div align="center" style="margin-bottom: 10px;">
<form name=sel>
{TOP_LEVEL_LABEL} <font id=special_type></font><br>
{THIRD_LEVEL_LABEL} <font id=special_date><select><option value='0'>Please Make Initial Selection</option></select></font><br>
{SECOND_LEVEL_LABEL} <font id=special_name><select><option value='0'>Please Make Initial Selection</option></select></font><br><br>
<input type="hidden" name="searchStr" value="" />
<input type="hidden" name="_a" value="viewCat" />
<input type="submit" value='Submit the form data'>
</div>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "ajaxMysql.php?data="+src+"&val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
req.send(null);
}
window.onLoad=dochange('special_type', -1); // initialize form selection
</script>
Let me know on this one:
---------------------
Start 'ajaxMySQL.php'
---------------------
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
print "Val: $val<br /><br />"; // debug val
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
$list = explode(',', $val);
$valSD = $list[0];
$valST = $list[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else {
$list = explode(',', $val);
$valSN = $list[0];
$valSD = $list[1];
$valST = $list[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
---------------------
End 'ajaxMySQL.php'
---------------------
And velow is purely a snippet of the code involved in a template file...
<div align="center" style="margin-bottom: 10px;">
<form name=sel>
{TOP_LEVEL_LABEL} <font id=special_type></font><br>
{THIRD_LEVEL_LABEL} <font id=special_date><select><option value='0'>Please Make Initial Selection</option></select></font><br>
{SECOND_LEVEL_LABEL} <font id=special_name><select><option value='0'>Please Make Initial Selection</option></select></font><br><br>
<input type="hidden" name="searchStr" value="" />
<input type="hidden" name="_a" value="viewCat" />
<input type="submit" value='Submit the form data'>
</div>
<script language=Javascript>
function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest(); } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};
function dochange(val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(src).innerHTML=req.responseText;
}
}
};
req.open("GET", "ajaxMysql.php?data="+src+"&val="+val);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=tis-620"); // set Header
req.send(null);
}
window.onLoad=dochange('special_type', -1); // initialize form selection
</script>
ASKER
Pretty much the same thing.
If I leave this:
echo "<select name='special_date' onChange=\"dochange('speci al_name', (this.value + ',' + $valST \">\n";
the second selection has no effect on the third.
With that in place, only the second 'ST' value in the debugging gets displayed.
Is there a change that also needs to be made to the JS code itself?
If I leave this:
echo "<select name='special_date' onChange=\"dochange('speci
the second selection has no effect on the third.
With that in place, only the second 'ST' value in the debugging gets displayed.
Is there a change that also needs to be made to the JS code itself?
ASKER
Alrighty...in an attempt to hopefully get this resolved, I have attached a file containing the 3 files directly involved.
They are all as they were originally.
Can you please take a look at each file and see if you have any further ideas?
code-examples.txt
They are all as they were originally.
Can you please take a look at each file and see if you have any further ideas?
code-examples.txt
THANKS!
2 Syntax errors found:
I forgot both terminating ")" from each of the doChange lines. :)
Replace the php code with the following code for ajaxMySQL.php
If you have any other errors then:
Please copy and paste your resultant HTML source code from each of the 4 steps (OUTPUT).
1. Initial view
2. Special type selection
3. Special date selection
4. Special name selection
=NerdsOfTech
2 Syntax errors found:
I forgot both terminating ")" from each of the doChange lines. :)
Replace the php code with the following code for ajaxMySQL.php
If you have any other errors then:
Please copy and paste your resultant HTML source code from each of the 4 steps (OUTPUT).
1. Initial view
2. Special type selection
3. Special date selection
4. Special name selection
=NerdsOfTech
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST)\">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
print 'Step 3<br />';
$arrVal = explode(',', $val);
print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST) \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
print 'Step 4<br />';
$arrVal = explode(',', $val);
print_r $arrVal;
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
If the above code works here is the debug free version.
USE the above version first to test.
Thanks for letting me help
PS if the above code doesnt work please follow up with the request for HTML output
=NerdsOfTech
USE the above version first to test.
Thanks for letting me help
PS if the above code doesnt work please follow up with the request for HTML output
=NerdsOfTech
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
// print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
// print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
// print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST)\">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
// print 'Step 3<br />';
$arrVal = explode(',', $val);
// print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST) \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
// print 'Step 4<br />';
$arrVal = explode(',', $val);
// print_r $arrVal;
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
// echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
ASKER
Firstly, thank you for all the help you are giving me with this.
I want you to know it is very much appreciated.
With the code above, I needed to change:
print_r $arrVal;
To:
print_r ($arrVal);
to correct the parse errors.
The second selection, still has no impact on the 3rd selection options.
Attached is the source of original page and the source after the initial selection.
source.txt
I want you to know it is very much appreciated.
With the code above, I needed to change:
print_r $arrVal;
To:
print_r ($arrVal);
to correct the parse errors.
The second selection, still has no impact on the 3rd selection options.
Attached is the source of original page and the source after the initial selection.
source.txt
Change this in the AJAX code
I think it it reinitializing after a selection is made automatically; which subsequently clears your second selection.
CHANGE FROM:
window.onLoad=dochange('sp ecial_type ', -1); // initialize form selection
TO:
if (! document.getElementsByName ('valST')) {
window.onLoad=dochange('sp ecial_type ', -1); // initialize form selection ONLY if object valST exist
}
***QUESTION***
Why is the first load without all of the hidden inputs valST valSD and valSN?
And why doesn't it output debug?
I think it it reinitializing after a selection is made automatically; which subsequently clears your second selection.
CHANGE FROM:
window.onLoad=dochange('sp
TO:
if (! document.getElementsByName
window.onLoad=dochange('sp
}
***QUESTION***
Why is the first load without all of the hidden inputs valST valSD and valSN?
And why doesn't it output debug?
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
// print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
// print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
// print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST)\">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
// print 'Step 3<br />';
$arrVal = explode(',', $val);
// print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST) \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
// print 'Step 4<br />';
$arrVal = explode(',', $val);
// print_r ($arrVal);
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
// echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
Correction on comment
// initialize form selection ONLY if object valST does not exist
// initialize form selection ONLY if object valST does not exist
ASKER
All code updated.
There will still no affect on the 3rd selection when using the 2nd selection.
I believe this is because these are different.
In the javascript function of dochange(src, val)
req.open("GET", "ajaxMysql.php?data="+src+ "&val="+va l);
But on the select it is this:
onChange=\"dochange('speci al_name', (this.value + ',' + $valST)\"
Should the $valST (and the others) be referenced in the JS function itself?
Or should there be separate functions for each level?
Additionally, when I made the changes, the first level selections were no longer present.
So I needed to create a default loop for that.
Please refer to the revised code attached.
code-examples2.txt
There will still no affect on the 3rd selection when using the 2nd selection.
I believe this is because these are different.
In the javascript function of dochange(src, val)
req.open("GET", "ajaxMysql.php?data="+src+
But on the select it is this:
onChange=\"dochange('speci
Should the $valST (and the others) be referenced in the JS function itself?
Or should there be separate functions for each level?
Additionally, when I made the changes, the first level selections were no longer present.
So I needed to create a default loop for that.
Please refer to the revised code attached.
code-examples2.txt
ASKER
Some revisions to the above to handle values being retained once the search gets performed.
This only affected the default values.
code-examples3.txt
This only affected the default values.
code-examples3.txt
ASKER
Any further ideas on this one?
Check to see what the actual output of the onChange line is...
it should look like this
... onChange="dochange('specia l_name', (this.value + ',' + $valST))"
make sure the closing parenthesis is there or else it won't work
it should look like this
... onChange="dochange('specia
make sure the closing parenthesis is there or else it won't work
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
// print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
// print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
// print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST))\">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
// print 'Step 3<br />';
$arrVal = explode(',', $val);
// print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST)) \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
// print 'Step 4<br />';
$arrVal = explode(',', $val);
// print_r ($arrVal);
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
// echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
Correction:
HTML output sample
<select name='special_date' onChange="dochange('specia l_name', (comapny, 2008-10-24)" >
Internal Code:
echo "<select name='special_date' onChange=\"dochange('speci al_name', (this.value + ',' + $valST))\">\n";
HTML output sample
<select name='special_date' onChange="dochange('specia
Internal Code:
echo "<select name='special_date' onChange=\"dochange('speci
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
// print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
// print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value)\" > $name";
}
} else if ($data=='special_date') {
// print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST))\">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
// print 'Step 3<br />';
$arrVal = explode(',', $val);
// print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + ',' + $valSD + ',' + $valST)) \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
// print 'Step 4<br />';
$arrVal = explode(',', $val);
// print_r ($arrVal);
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
// echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
I replaced the comma delimiter with bar '|' this that instead
Correction #2:
HTML output sample
<select name='special_date' onChange="dochange('specia l_name', (company|2008-10-24));" >
Internal Code:
echo "<select name='special_date' onChange=\"dochange('speci al_name', (this.value + '|' + $valST)); \">\n";
Correction #2:
HTML output sample
<select name='special_date' onChange="dochange('specia
Internal Code:
echo "<select name='special_date' onChange=\"dochange('speci
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
// print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
// print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value);\" > $name";
}
} else if ($data=='special_date') {
// print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + '|' + $valST)); \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
// print 'Step 3<br />';
$arrVal = explode('|', $val);
// print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + '|' + $valSD + '|' + $valST)); \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
// print 'Step 4<br />';
$arrVal = explode('|', $val);
// print_r ($arrVal);
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
// echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
ASKER
So just replace the contents of ajaxMysql.php with that above?
Correct
ASKER
All done, still no luck on the 2nd selection updating the 3rd selection.
Here is the initial page load source:
<form name="sel">
Type: <font id="special_type">
<input name="special_type" id="special_type" value="Law" onclick="dochange('special _date', this.value)" checked="checked" type="radio"> Law
<input name="special_type" id="special_type" value="Company" onclick="dochange('special _date', this.value)" type="radio"> Company
</font><br>
Date: <font id="special_date">
<select name="special_date" onchange="dochange('specia l_name', this.value)">
<option value="2008-10-18">2008-10 -18</optio n>
<option value="2008-10-17">2008-10 -17</optio n>
</select>
</font><br>
Name: <font id="special_name">
<select name="special_name">
<option value="ALL">All</option>
<option value="Name 01">Name 01</option>
<option value="Name 02">Name 02</option>
</select>
</font><br><br>
<input name="searchStr" value="" type="hidden">
<input name="_a" value="viewCat" type="hidden">
<input value="Submit the form data" type="submit">
</form>
And here is the source again after making the first selection:
<form name="sel">
Type: <font id="special_type">
<input name="special_type" id="special_type" value="Law" onclick="dochange('special _date', this.value)" checked="checked" type="radio"> Law
<input name="special_type" id="special_type" value="Company" onclick="dochange('special _date', this.value)" type="radio"> Company
</font><br>
Date: <font id="special_date"><select name="special_date" onchange="dochange('specia l_name', (this.value + '|' + Company)); ">
<option value="0">Please Select</option>
<option value="2008-10-18">2008-10 -18</optio n>
<option value="2008-10-17">2008-10 -17</optio n>
<option value="2008-10-16">2008-10 -16</optio n>
<option value="2008-10-15">2008-10 -15</optio n>
</select>
<input name="valST" value="Company" type="hidden"><input name="valSD" value="" type="hidden"><input name="valSN" value="" type="hidden"></font><br>
Name: <font id="special_name">
<select name="special_name">
<option value="ALL">All</option>
<option value="Name 01">Name 01</option>
<option value="Name 02">Name 02</option>
</select>
</font><br><br>
<input name="searchStr" value="" type="hidden">
<input name="_a" value="viewCat" type="hidden">
<input value="Submit the form data" type="submit">
</form>
Does this:
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(sr c).innerHT ML=req.res ponseText;
}
}
};
req.open("GET", "ajaxMysql.php?data="+src+ "&val="+va l);
req.setRequestHeader("Cont ent-Type", "application/x-www-form-ur lencoded;c harset=tis -620"); // set Header
req.send(null);
}
need to be changed so the second selection affects the 3rd?
Here is the initial page load source:
<form name="sel">
Type: <font id="special_type">
<input name="special_type" id="special_type" value="Law" onclick="dochange('special
<input name="special_type" id="special_type" value="Company" onclick="dochange('special
</font><br>
Date: <font id="special_date">
<select name="special_date" onchange="dochange('specia
<option value="2008-10-18">2008-10
<option value="2008-10-17">2008-10
</select>
</font><br>
Name: <font id="special_name">
<select name="special_name">
<option value="ALL">All</option>
<option value="Name 01">Name 01</option>
<option value="Name 02">Name 02</option>
</select>
</font><br><br>
<input name="searchStr" value="" type="hidden">
<input name="_a" value="viewCat" type="hidden">
<input value="Submit the form data" type="submit">
</form>
And here is the source again after making the first selection:
<form name="sel">
Type: <font id="special_type">
<input name="special_type" id="special_type" value="Law" onclick="dochange('special
<input name="special_type" id="special_type" value="Company" onclick="dochange('special
</font><br>
Date: <font id="special_date"><select name="special_date" onchange="dochange('specia
<option value="0">Please Select</option>
<option value="2008-10-18">2008-10
<option value="2008-10-17">2008-10
<option value="2008-10-16">2008-10
<option value="2008-10-15">2008-10
</select>
<input name="valST" value="Company" type="hidden"><input name="valSD" value="" type="hidden"><input name="valSN" value="" type="hidden"></font><br>
Name: <font id="special_name">
<select name="special_name">
<option value="ALL">All</option>
<option value="Name 01">Name 01</option>
<option value="Name 02">Name 02</option>
</select>
</font><br><br>
<input name="searchStr" value="" type="hidden">
<input name="_a" value="viewCat" type="hidden">
<input value="Submit the form data" type="submit">
</form>
Does this:
function dochange(src, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
if (req.readyState==4) {
if (req.status==200) {
document.getElementById(sr
}
}
};
req.open("GET", "ajaxMysql.php?data="+src+
req.setRequestHeader("Cont
req.send(null);
}
need to be changed so the second selection affects the 3rd?
I got it...
Logic/Syntax Combo Error:
single quotes '
around the php variables inside of the onChange actions
:)
Replace .php file with the following
Logic/Syntax Combo Error:
single quotes '
around the php variables inside of the onChange actions
:)
Replace .php file with the following
<?php
require_once 'ini.inc.php';
require_once 'includes'.CC_DS.'global.inc.php';
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("content-type: application/x-javascript; charset=tis-620");
$data=$_GET['data'];
$val=$_GET['val'];
// print "data: $data<br />val: $val<br /><hr /><br />"; // debug get
$dbhost = $glob['dbhost'];
$dbuser = $glob['dbusername'];
$dbpass = $glob['dbpassword'];
$dbname = $glob['dbdatabase'];
$valST = "";
$valSD = "";
$valSN = "";
mysql_pconnect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to MySQL server");
if ($data=='special_type') {
// print 'Step 1<br />';
$result=mysql_db_query($dbname,"select distinct special_type from CubeCart_inventory ORDER BY special_type DESC");
while(list($name)=mysql_fetch_array($result)){
echo "<input type='radio' name='special_type' id='special_type' $default_checked value=\"$name\" onClick=\"dochange('special_date', this.value);\" > $name";
}
} else if ($data=='special_date') {
// print 'Step 2<br />';
$valST = $val;
echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + '|' + '$valST')); \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_date FROM CubeCart_inventory WHERE special_type = '$valST' ORDER BY special_date DESC LIMIT 4");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='special_name') {
// print 'Step 3<br />';
$arrVal = explode('|', $val);
// print_r $arrVal;
$valSD = $arrVal[0];
$valST = $arrVal[1];
echo "<select name='special_name' onChange=\"dochange('completed', (this.value + '|' + '$valSD' + '|' + '$valST')); \">\n";
echo "<option value='0'>Please Select</option>\n";
$result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$valST' AND special_date = '$valSD' ORDER BY special_name ASC ");
while(list($name)=mysql_fetch_array($result)){
echo "<option value=\"$name\" >$name</option> \n" ;
}
echo "</select>\n";
} else if ($data=='completed') {
// print 'Step 4<br />';
$arrVal = explode('|', $val);
// print_r ($arrVal);
$valSN = $arrVal[0];
$valSD = $arrVal[1];
$valST = $arrVal[2];
}
echo '<input type="hidden" name="valST" value="' . $valST . '" />';
echo '<input type="hidden" name="valSD" value="' . $valSD . '" />';
echo '<input type="hidden" name="valSN" value="' . $valSN . '" />';
// echo "DEBUG<br /><br />ST: $valST<br />SD: $valSD<br />SN: $valSN<br />"; // debug
?>
ASKER
You know, I have to run a few further tests....but I believe we now have winner here! :D
ASKER
As above, all is looking great!
Thank you so very, very much.
Your help is so incredibly appreciated!
One last request, and this one is minor but would be nice.
When the search gets submitted, it results in this:
index.php?
special_type=Company&
special_date=2008-10-17&
valST=Company&
valSD=&
valSN=&
special_name=Name+01&
valST=Company&
valSD=2008-10-17&
valSN=&
searchStr=&
_a=viewCat
Is it possible to get it so its only this:
index.php?
special_type=Company&
special_date=2008-10-17&
special_name=Name+01&
searchStr=&
_a=viewCat
I have broken down both of the above so each is on a separate line and easier to read.
In reality it looks like this:
http://192.168.1.71/index.php?special_type=Company&special_date=2008-10-17&valST=Company&valSD=&valSN=&special_name=Name+01&valST=Company&valSD=2008-10-17&valSN=&searchStr=&_a=viewCat
What do you think?
Is it possible to remove/hide all the valST/valSD/valSN instances when it actually gets submitted?
Thank you so very, very much.
Your help is so incredibly appreciated!
One last request, and this one is minor but would be nice.
When the search gets submitted, it results in this:
index.php?
special_type=Company&
special_date=2008-10-17&
valST=Company&
valSD=&
valSN=&
special_name=Name+01&
valST=Company&
valSD=2008-10-17&
valSN=&
searchStr=&
_a=viewCat
Is it possible to get it so its only this:
index.php?
special_type=Company&
special_date=2008-10-17&
special_name=Name+01&
searchStr=&
_a=viewCat
I have broken down both of the above so each is on a separate line and easier to read.
In reality it looks like this:
http://192.168.1.71/index.php?special_type=Company&special_date=2008-10-17&valST=Company&valSD=&valSN=&special_name=Name+01&valST=Company&valSD=2008-10-17&valSN=&searchStr=&_a=viewCat
What do you think?
Is it possible to remove/hide all the valST/valSD/valSN instances when it actually gets submitted?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
It was fun figuring it all out. Thanks!
Check the final edit above and see if it works - if it does, please tag me as the solution above.
=NerdsOfTech
Check the final edit above and see if it works - if it does, please tag me as the solution above.
=NerdsOfTech
ASKER
Absolutely fantastic!
All is working perfectly.
Sincerely, thank you so very much for all your help on this one.
All is working perfectly.
Sincerely, thank you so very much for all your help on this one.
ASKER
Once ore, thank you, so very, very much!
Open in new window