Morning people,

I'm trying to embid php in javascript function and pass the information php read to a separate javascript page using js function

<script type="text/javascript" language="javascript">
	function alerting()
	{
		//var getinformation = new Array(40);
	var information += <?php $sql = $conn->query("select valgroup_id,valgroup_desc from validating_group LIMIT 1"); 
	    
							if(mysql_num_rows($sql) > 0)
							{
								while($rec = $conn->fetchArray($sql))
								{
									$id = $rec['valgroup_id']; 
									$desc = $rec['valgroup_desc'];
									//echo $id;
								}
							}
						?>
	document.write(information+"  :sizwe ");
	// return information;
	}  
</script>

Thank you in advince.

It depends on exactly what you are trying to do?

As written the PHP code will execute once before the page is served. It will dynamically add to your javascript variable information . This will be fine (when debugged) if that's what you want.

What it WON'T do is run the PHP code each time the javascript function alerting() is called. If this is the functionality you want then you have to learn AJAX, for which there are plenty of tutorials on the web.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.