2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by mstatdaniweb
0

we can pass the php value to javascript by the following method, I will give you a sample to pass a single variable

//PHP declaration
<?php $name='raja'?>
//Javascript
	<script type = 'text/javascript'>
		var hp="<?php echo $name; ?>";
		alert (hp);
	</script>

Hope this helps you to share your value pass to javascript

0

Thanks for your reply, but this not exactly what i had in mind.

The problem is that when i run a loop in php like this:

<?
for($i=0; $i<$something; $i++)
{?>
<script type = 'text/javascript'>
var hp="<?php echo $i; ?>";
alert (hp);
</script>
<?
}
?>

to the hp var there would be assigned only highest value of something-1; cos js works client side, and php was executed before js.

My point is to pass also temporary values, not only the highest.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.