Jump to content

ajax/php select boxes ALMOST always works...


mikefrederick

Recommended Posts

Thanks a lot if you can help with this. My script for chained select boxes works all the time other than in IE. in IE, it only repopulates the second box certain times. I am populating from databases. I can't figure it out....

See them at ivoiresondage.com/index.php.

 

important script in header :

function getCountries(sel)
{
var countryCode = sel.options[sel.selectedIndex].id;
var rid = sel.options[sel.selectedIndex].value;
document.getElementById('dhtmlgoodies_country').options.length = 0;	// Empty city select box
if(countryCode.length>0){

	var index = ajax.length;
	ajax[index] = new sack();

	ajax[index].requestFile = 'populate.php?rid='+rid+'&countryCode='+countryCode;	// Specifying which file to get
	ajax[index].onCompletion = function(){ createCountries(index) };	// Specify function that will be executed after file has been found
	ajax[index].runAJAX();		// Execute AJAX function
}
}

function createCountries(index)
{
var obj = document.getElementById('dhtmlgoodies_country');
eval(ajax[index].response);	// Executing the response from Ajax as Javascript code	
}

 

 

 

Associated files:

-ivoiresondage.com/ajax.js

-ivoiresondage.com/populate.php.

code for populate.php:

<?php

include "config.php";
$action=$_GET["countryCode"];
switch($action)
{
case "getcountries":
	$rid=$_REQUEST["rid"];
	$sql="select * from departments where rid='$rid' order by name";
	$res=mysql_query($sql);
	$y.="obj.options[obj.options.length] = new Option('...','...');\n";
	while($row=mysql_fetch_array($res))
	{
		$y.="obj.options[obj.options.length] = new Option('$row[name]','$row[id]');\n";

	}

	echo $y;	break;


}


$actionz=$_REQUEST["category"];
switch($actionz)
{

case "test":
$cid=$_GET["cid"];
	$sqltt="select * from departments where rid='$rid' order by name";
	$restt=mysql_query($sqltt);

	$out.="obj.options[obj.options.length] = new Option('Select a State','1');\n";
	while($rowtt=mysql_fetch_array($restt))
	{
		$out.="obj.options[obj.options.length] = new Option('$rowtt[name]','$rowtt[id]');\n";
	}

	echo $out;
break;

}




?>

 

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/93944-ajaxphp-select-boxes-almost-always-works/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.