Hello,

I'm trying to pass a $counter2 value from php loop to javascript, but $counter2 is incremented so I'm passing the highest value of $counter2, which i not what I want to do. Is there a way to combine values with html identifiers and pass them to js?I would be grateful for assistance.

Link to code:
http://studentuczy.ayz.pl/Calendar/calendar.txt
What is it?
http://studentuczy.ayz.pl/Calendar/calendar.php

Thank you in advance.

Member Avatar for rajarajan2017

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

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.

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.