aoghsshebron Posted March 20, 2006 Share Posted March 20, 2006 i want to pass php value to JavaScripthow can i do thatvar abc=$abc?????????i need to do my project please help me Link to comment Share on other sites More sharing options...
Guest Kiwi Posted March 20, 2006 Share Posted March 20, 2006 If you're using an external Js file you could do something like this: <?header('Content-type: text/js');?>var abc = <?=abc?> If not, you can just echo the vars bitween you're Js code, like Html. Link to comment Share on other sites More sharing options...
aoghsshebron Posted March 20, 2006 Author Share Posted March 20, 2006 If you're using an external Js file you could do something like this:<?header('Content-type: text/js');?>var abc = <?=abc?> If not, you can just echo the vars bitween you're Js code, like Html. <{POST_SNAPBACK}> if <OPTION value=$sFullname>($sFullname is php value)the result is "$sFullname "cannot read the the value~~how can i pass it in http option Link to comment Share on other sites More sharing options...
scott100 Posted March 20, 2006 Share Posted March 20, 2006 Put the php variable in a hidden html inputuse javascript to access the inputthis works, save as whatever.php <?php ini_set ('display_errors', 1);error_reporting (E_ALL & ~E_NOTICE);$val="hello";print"Value in PHP: $val";print'<input type="hidden" id="secret" value="'. $val. '" />';?><script> var getVal=document.getElementById('secret').value; document.write("<br />Value in Javascript: "+getVal);</script> Link to comment Share on other sites More sharing options...
aoghsshebron Posted March 20, 2006 Author Share Posted March 20, 2006 Put the php variable in a hidden html inputuse javascript to access the inputthis works, save as whatever.php<?php ini_set ('display_errors', 1);error_reporting (E_ALL & ~E_NOTICE);$val="hello";print"Value in PHP: $val";print'<input type="hidden" id="secret" value="'. $val. '" />';?><script> var getVal=document.getElementById('secret').value; document.write("<br />Value in Javascript: "+getVal);</script> <{POST_SNAPBACK}> thank a lot^^i got it Link to comment Share on other sites More sharing options...
scott100 Posted March 20, 2006 Share Posted March 20, 2006 No problemI managed another way if it helps: <?php$val="I am from php";print '<script>alert("javascript alerts: "+"'.$val.'");</script>';?> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now