sungpeng Posted November 30, 2011 Share Posted November 30, 2011 <?php $going=''; $name='<span id="name"></span>'; echo "$name"; //results : stevengoh --- wanted $going=substr($name, 1, 17); echo "$name"; //results : <span id="going"> ---- don't want ?> Is it possible to store in php the results of variable id="going" javascript instead of <span id="going"></span>?. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 30, 2011 Share Posted November 30, 2011 really not sure what you want, is it something along these lines? $name = 'stevengoh'; $going = '<span id="'.$name.'">'.$name.'</span>'; echo $going; Quote Link to comment Share on other sites More sharing options...
sungpeng Posted November 30, 2011 Author Share Posted November 30, 2011 hi master, <script> var name = document.getElementById('name'); var greeting = document.createTextNode('stevengoh'); name.appendChild(greeting); </script> the above code is like that.. Wanna to get the name "stevengoh" into php variable from javascript.. Pls help Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted November 30, 2011 Share Posted November 30, 2011 in that case you need to make an AJAX request. Quote Link to comment Share on other sites More sharing options...
sungpeng Posted November 30, 2011 Author Share Posted November 30, 2011 i searched for days and still cannot hit any ball. Can give me more details so I can work on it? Quote Link to comment Share on other sites More sharing options...
Drummin Posted November 30, 2011 Share Posted November 30, 2011 I know this is php and not JS or ajax but this will create the variable called whatever you define $name as. <?php $name="stevengoh"; $$name="$name"; echo "$stevengoh"; ?> Quote Link to comment Share on other sites More sharing options...
sungpeng Posted November 30, 2011 Author Share Posted November 30, 2011 Hi Drummin, not that simple.. Quote Link to comment Share on other sites More sharing options...
sungpeng Posted November 30, 2011 Author Share Posted November 30, 2011 <html> <head> <script type="text/javascript"> function loadXMLDoc() { var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("myDiv").innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST","demo_post2.asp",true); xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlhttp.send("fname=Henry&lname=Ford"); } </script> </head> <body> <h2>AJAX</h2> <button type="button" onclick="loadXMLDoc()">Request data</button> <div id="myDiv"></div> </body> </html> Close to solved.. hi how to get the data from demo_post2.asp? i try _post["fname"]; unsuccessful.. Quote Link to comment 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.