Solved

AJAX 3 Level Selections

Posted on 2008-10-20
43
481 Views
Last Modified: 2013-12-13
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.
---------------------

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>

Open in new window

0
Comment
Question by:SemperFiWS
  • 23
  • 20
43 Comments
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22765774
Line 43 to filter with previous selection. Use "AND" SQL operator
          $result=mysql_db_query($dbname,"SELECT distinct special_name FROM CubeCart_inventory WHERE special_type = '$val' AND special_date = '$val2' ORDER BY special_name ASC ");

Open in new window

0
 

Author Comment

by:SemperFiWS
ID: 22768620
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.

0
 

Author Comment

by:SemperFiWS
ID: 22772344
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?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22772389
You could always collect $_POST values from each selection

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

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22772392
Just be careful you safe check the values so you won't be vulnerable to SQL Injection Attack.

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

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22772459
$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 == ""
// Round 4 special_type != "" AND special_date != "" AND special_date != ""
 
// put code here for security against SQL Injection Attack
0
 

Author Comment

by:SemperFiWS
ID: 22772464
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?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22774628
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
0
 

Author Comment

by:SemperFiWS
ID: 22780012
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?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22780688
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
---------------------

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>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22780719
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>

Open in new window

0
 

Author Comment

by:SemperFiWS
ID: 22781179
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.

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22781652
doh!

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>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22781661
I reversed the explode statement around accidentally

Now you should get results with no errors. Let me know.
0
 

Author Comment

by:SemperFiWS
ID: 22782475
The second selection still has no effect on the 3rd selection values.
0
 

Author Comment

by:SemperFiWS
ID: 22788190
Any further ideas on this one?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22790780
Are you getting values from the debug now? Let me know.
0
 

Author Comment

by:SemperFiWS
ID: 22790821
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.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22794202
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>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22794206
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>

Open in new window

0
 

Author Comment

by:SemperFiWS
ID: 22798027
Pretty much the same thing.

If I leave this:
echo "<select name='special_date' onChange=\"dochange('special_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?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:SemperFiWS
ID: 22801078
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
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22802260
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
<?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

 

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22802265
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
<?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

 

?>

Open in new window

0
 

Author Comment

by:SemperFiWS
ID: 22808191
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
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22809569
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('special_type', -1); // initialize form selection

TO:


if (! document.getElementsByName('valST')){
   window.onLoad=dochange('special_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?
<?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

 

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22809570
Correction on comment
// initialize form selection ONLY if object valST does not exist
0
 

Author Comment

by:SemperFiWS
ID: 22812599
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="+val);

But on the select it is this:
onChange=\"dochange('special_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
0
 

Author Comment

by:SemperFiWS
ID: 22813124
Some revisions to the above to handle values being retained once the search gets performed.
This only affected the default values.
code-examples3.txt
0
 

Author Comment

by:SemperFiWS
ID: 22823871
Any further ideas on this one?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22825948
Check to see what the actual output of the onChange line is...

it should look like this

... onChange="dochange('special_name', (this.value + ',' + $valST))"

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

 

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22825987
Correction:
HTML output sample
<select name='special_date'  onChange="dochange('special_name', (comapny, 2008-10-24)" >

Internal Code:
          echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + ',' + $valST))\">\n";
<?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

 

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22826051
I replaced the comma delimiter with bar '|' this that instead

Correction #2:
HTML output sample
<select name='special_date'  onChange="dochange('special_name', (company|2008-10-24));" >

Internal Code:
          echo "<select name='special_date' onChange=\"dochange('special_name', (this.value + '|' + $valST)); \">\n";
<?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

 

?>

Open in new window

0
 

Author Comment

by:SemperFiWS
ID: 22826404
So just replace the contents of ajaxMysql.php with that above?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22826566
Correct
0
 

Author Comment

by:SemperFiWS
ID: 22826728
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('special_name', this.value)">

                              <option value="2008-10-18">2008-10-18</option>
                              
                              <option value="2008-10-17">2008-10-17</option>            
                              </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('special_name', (this.value + '|' + Company)); ">
<option value="0">Please Select</option>

<option value="2008-10-18">2008-10-18</option>
<option value="2008-10-17">2008-10-17</option>
<option value="2008-10-16">2008-10-16</option>
<option value="2008-10-15">2008-10-15</option>
</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(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);
}

need to be changed so the second selection affects the 3rd?
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22826830
I got it...
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

 

?>

Open in new window

0
 

Author Comment

by:SemperFiWS
ID: 22826964
You know, I have to run a few further tests....but I believe we now have winner here! :D
0
 

Author Comment

by:SemperFiWS
ID: 22827132
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?
0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 500 total points
ID: 22827275
Sure can!
I am glad it is working see if this works

// comment the input echoes
<?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

 

?>

Open in new window

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 22829170
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
0
 

Author Comment

by:SemperFiWS
ID: 22832058
Absolutely fantastic!

All is working perfectly.
Sincerely, thank you so very much for all your help on this one.

0
 

Author Closing Comment

by:SemperFiWS
ID: 31508086
Once ore, thank you, so very, very much!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now