Can't get any javascript code to run!

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
dave_2011
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 10:38 am

Can't get any javascript code to run!

Post 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>

<? } ?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post by Weirdan »

Some extra info: The page below is called by a javascript function (using ajax to fill the drop downs)
Post that function.
dave_2011
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 10:38 am

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

Post 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 :)
dave_2011
Forum Newbie
Posts: 3
Joined: Thu Jul 21, 2011 10:38 am

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

Post 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!
Post Reply