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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.