baho Posted August 4, 2006 Share Posted August 4, 2006 How can i pass the javascript variable 'i' value to php variable '$k'?<html><body><script language="javascript">var i=5;<?php $k;?></script></body></html>Thanx. Quote Link to comment https://forums.phpfreaks.com/topic/16566-javascript-variable-to-php-variable/ Share on other sites More sharing options...
paul2463 Posted August 4, 2006 Share Posted August 4, 2006 [code]<html><body><script language="javascript">var $i=5;<?php $k = $i;?></script></body></html>[/code]when you create the javascript variable, make it readable as a variable by PHP by using the PHP standard method of giving it a $ at the beginning. Quote Link to comment https://forums.phpfreaks.com/topic/16566-javascript-variable-to-php-variable/#findComment-69350 Share on other sites More sharing options...
baho Posted August 4, 2006 Author Share Posted August 4, 2006 thanx, but this code doesn't work[color=green]<script language=javascript> $k=5; alert ($k); alert ("<?php echo $k?>"); <?php $i=$k;?> alert ("<?php echo $i?>");</script>[/color]Can you tell me what is the problem here? Quote Link to comment https://forums.phpfreaks.com/topic/16566-javascript-variable-to-php-variable/#findComment-69404 Share on other sites More sharing options...
stillatmycomputer Posted August 5, 2006 Share Posted August 5, 2006 PHP code is processed by the server before the browser processes your javascript. Set your variables first in PHP.[color=orange]<script language="javascript">[/color] [color=orange]var [/color]<?php $k=5; echo('[color=orange]$k=[/color]'.$k); ?>[color=green];[/color] [color=orange]alert($k);[/color] [color=orange]alert("[/color]<?php echo($k); ?>[color=orange]");[/color] <?php $i=$k; ?> [color=orange]alert("[/color]<?php echo $i ?>"[color=orange]);[/color][color=orange]</script>[/color] Quote Link to comment https://forums.phpfreaks.com/topic/16566-javascript-variable-to-php-variable/#findComment-69598 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.