Page 1 of 1

Can't get any javascript code to run!

Posted: Thu Jul 21, 2011 10:49 am
by dave_2011
Hello,

Been battling with this all day, I have a PHP file which contains a mix of PHP and Javascript to autofil some drop down boxes. The PHP code works fine, but I can't seem to get any javascript code to run at all. Nothing.

Some extra info: The page below is called by a javascript function (using ajax to fill the drop downs)

Here's my code from the PHP File, if anyone can help, it'd be much appreciated. Thanks.

I've put in an alert box in the code, just to prove it won't work!

Code: Select all

<? $hand=$_GET['hand'];

$link = mysql_connect('xxxxxxx'); //change the configuration if required
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db('xxxxxx'); //change this if required
$query="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ;

$result=mysql_query($query);

?>

<script type="text/javascript">
        alert("I am an alert box!");
</script>

<? if(mysql_num_rows($result) == 1){
		?>
		
		<select name="loft" id="loft" onmouseover="getSet(this.value)">
					<option selected="selected" value="#">Select Loft</option>

			<? while($row=mysql_fetch_array($result)) { ?>
				<option selected="selected" value="<?=$row['loft']?>"><?=$row['loft']?></option>
			<? } ?>
		</select>
	<? }else{ ?>
		
	<select name="loft" id="loft" onchange="getSet(this.value)">
		<option selected="selected" value="#">Select Loft</option>
		<? while($row=mysql_fetch_array($result)) { ?>
			<option value="<?=$row['loft']?>"><?=$row['loft']?></option>
		<? } ?>
	</select>

<? } ?>

Re: Can't get any javascript code to run!

Posted: Thu Jul 21, 2011 12:04 pm
by Weirdan
Some extra info: The page below is called by a javascript function (using ajax to fill the drop downs)
Post that function.

Re: Can't get any javascript code to run!

Posted: Fri Jul 22, 2011 3:41 am
by dave_2011

Code: Select all

//clicked on hand to get loft
function getLoft(str)
{
var xmlhttp;    
if (str=="")
  {
  document.getElementById("loft-div").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("loft-div").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","findLoft.php?hand="+str,true);
xmlhttp.send();
}
}

This is the function that calls the above mentioned php code.

Thanks in advance :)

Re: Can't get any javascript code to run!

Posted: Fri Jul 22, 2011 5:05 am
by dave_2011
Also, another point of interest is that when the PHP file mentioned above is included in another ASP page, the drop downs won't populate with data from the database, unless I put it in an <iframe>. Any thoughts on that more than welcome. Thanks again!