Hey,
I've just come across a piece of code that seems to have just stopped working even though I have been assured by my host they have changed nothing on the server.
It's a script that uses two drop down menus and updates the second one depending on what has been selected in the first.
Now, this is the code - sorry if it's a bit long:
<?
//read the database
$getfilequery = "SELECT FILES_CATEGORIES_SUB.subcategory_id,
FILES_CATEGORIES_SUB.subcategory_name,
FILES.subid,
FILES.title,
FILES.fileid FROM FILES, FILES_CATEGORIES_SUB WHERE FILES.subid=FILES_CATEGORIES_SUB.subcategory_id ORDER BY FILES_CATEGORIES_SUB.subcategory_name ASC";
$getfilecategory = mysql_query($getfilequery, $conn);
//write the table
echo
"<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr>
<td align=\"left\" valign=\"top\">";
// write the country's listbox...
echo "<p>Choose file category...</p><p><select name=\"country\" size=\"10\" style=\"width: 100%\" onchange=\"countryselected(this);\">\n";
// write the entry code for the javascript...\n is used to force a new line so the resultant code is more readable
$sJavaScript = "function countryselected(elem){\n for (var i = document.f1.city.options.length; i >= 0; i--){ \n document.f1.city.options[i] = null;\n";
// loop through the database..
$sLastCountry="";
while ( $row2 = mysql_fetch_array($getfilecategory))
{
// is this a new country?
If ($sLastCountry!=$row2["subcategory_name"]){
// if yes, add the entry to the countrys listbox
$sLastCountry = $row2["subcategory_name"];
echo "\n<option value='".$row2["subid"]."' >".$sLastCountry."</option>";
// and add a new section to the javascript...
$sJavaScript = $sJavaScript."}\n"."if (elem.options[elem.selectedIndex].value==".$row2["subid"]."){\n";
}
// and add a new city line to the javascript
$sJavaScript = $sJavaScript."document.f1.city.options[document.f1.city.options.length] = new Option('".$row2["title"]."','".$row2["fileid"]."');\n";
}
// finish the country's listbox
echo "</select></p>";
// create the city listbox for no selection
echo "<p>Select file to add...</p><p><select name=\"city\" size=\"10\" style=\"width: 100%\" >";
echo "<option></option>";
echo "</select></p>";
echo "</td>
</tr>
</table>";
// finish the javascript and write out
$sJavaScript = $sJavaScript."\n}\n}\n";
echo "\n<SCRIPT LANGUAGE=\"JavaScript\">";
echo "\n".$sJavaScript."\n</SCRIPT>\n";
//close the form
?>
Now, I can't see what's wrong - I haven't changed a thing and to be sure I uploaded a copy of an older file that I know for sure worked...
Any ideas - I'm totally stumped!
Cheers,
Chris