I guess I am just over my head. I copy and paste this stuff and it still does not work. Something about me and javascript just don't mix.
here is the html(php in this case with no php code) page in its entirety:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<?php include 'my_functions.php'; ?>
<script type="text/javascript">
var request = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
request = false;
}
}
@end @*/
if (!request && typeof XMLHttpRequest != 'undefined') {
request = new XMLHttpRequest();
}
function fillSelect(country) {
var url = "csa_ajax.php?country=" + escape(country);
request.open("GET", url, true);
request.onreadystatechange = go;
request.send(null);
}
function go() {
if (request.readyState == 4) {
if (request.status == 200) {
var response = request.responseText;
var list=document.getElementById("city");
var cities=response.split('|');
for (i=1; i<cities.length; i++) {
var x=document.createElement('option');
var y=document.createTextNode(cities[i]);
x.appendChild(y);
list.appendChild(x);
}
}
}
}
function initCs() {
var country=document.getElementById('country');
country.onchange=function() {
if(this.value!="") {
var list=document.getElementById("city");
while (list.childNodes[0]) {
list.removeChild(list.childNodes[0])
}
fillSelect(this.value);
}
}
fillSelect(country.value);
}
</script>
<title></title>
</head>
<body>
<form method="post" action="#">
<p><label>country: <select id="country" name="country">
<option value="United Kingdom">United Kingdom</option>
<option value="United States">United States</option>
<option value="Australia">Australia</option>
<option value="Japan">Japan</option>
</select></label>
<label>city: <select id="city" name="city">
</select></label></p>
</form>
</body>
</html>
And here is the other file, which confused me on the host site. The url referenced in the javascript calls for csa_ajax.php, but the instructions on the site said to put this code in a csa_ajax.js. Not knowing which to do I tried just that code in a php and just that code in a js and just that code in BOTH a php and a js file.
The contents of that file are as follows:
PHP Code:
<?php
function doIt($country) {
switch ($country) {
case "United Kingdom":
return array('London','Manchester','Birmingham','Liverpool','Edinburgh','Cardiff','Belfast');
break;
case "United States":
return array('Washington DC','New York','Los Angeles', 'Chicago');
break;
case "Australia":
return array('Canberra','Melbourne','Sydney', 'Brisbane');
break;
case "Japan":
return array('Tokyo','Osaka','Fukuoka','Sendai','Sapporo');
break;
}
}
$country=@$_GET['country'];
$cities=doIt($country);
foreach ($cities as $city) {
echo '|'.$city;
}
?>
All the files are in the same directory (the web root) and the second box does nothing at all. Any help?
The url for it failing to do anything in motion is:
www.thebrasse.com/chain_select.php
Darn thing is really hurting my schedule now.
Bookmarks