User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,031 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,478 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

AJAX generated <select> and FIREFOX

Join Date: Sep 2007
Posts: 25
Reputation: roy-- is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
roy-- roy-- is offline Offline
Light Poster

AJAX generated <select> and FIREFOX

  #1  
Sep 11th, 2007
Hello,

I am trying to implement two cascading <select> boxes. the second box's options would be fetched from a mysql db via a PHP script.

it works fine on IE.

Problems rise when it comes to Firefox, the form would not submit the value from the second <select> box.

I have the feeling that we need to return the name/value pairs of data and generate the <option>s on client-side, I just dont know how to do it using DOM.

Please advise..

Below is code for both the JS and PHP scripts:

PHP script

<?php
$countrycode=$_GET["countrycode"];

include("key.php");
$connection = mysql_connect($mysql_host_name,$username, $password) or die(mysql_error());
$db = mysql_select_db($mysql_db_name,$connection) or die ("Couldn't select database.");

mysql_select_db("getCities", $connection);

$sql="SELECT city_id, countrycode, name, nr_hotels FROM getCities WHERE countrycode = '".$countrycode."' ORDER BY name";

$result = mysql_query($sql);
echo "
<select name=\"city_id\"  style=\"font-family:Verdana, Arial, Helvetica, sans-serif; font-weight: bold; font-size:15px \">
<OPTION VALUE=\"0\">-----------------------------------------
";

$options="";

while($row = mysql_fetch_array($result))
 {
 
$cityname=$row["name"];
$city_id=$row["city_id"];
$nr_hotels=$row["nr_hotels"];
$options.="<OPTION VALUE=\"$city_id\">".$cityname." (".$nr_hotels." hotels)";

}
echo $options;

echo "</select>";

mysql_close($connection);
?>

Javascript

var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request")
 return
 }
var url="ajax.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 } 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 10:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC