husslela03 Posted April 15, 2010 Share Posted April 15, 2010 How do I place an xmlhttp.responseText into a variable. where it is set up now is it in document.getElementById('word').innerHTML=xmlhttp.responseText and i would like to place it in a variable called var word, and then be able to do things to it. I'm implementing a game where a user guesses letters. Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 I assume you haven't tried before asking. var word = xmlhttp.responseText; Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/#findComment-1042087 Share on other sites More sharing options...
husslela03 Posted April 15, 2010 Author Share Posted April 15, 2010 Actually I did try that. However, when I did a document.write(theWord); in the body area of the html document...it did not display... Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/#findComment-1042089 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Show me the code. Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/#findComment-1042142 Share on other sites More sharing options...
husslela03 Posted April 15, 2010 Author Share Posted April 15, 2010 <?php echo 'Welcome to Lingo'; ?> <html> <head> </head> <body> <script type="text/javascript"> var xmlhttp; var gameWord; function myfunction() { //variable to hold the word from the server if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(var gameWord) { if(xmlhttp.readyState==4) { document.getElementById('word').innerHTML=xmlhttp.responseText; } } xmlhttp.open("POST", "get_word.php", true); xmlhttp.send(null); } document.write(gameWord); </script> <form name="myLingo"> <input type="button" value="New Word" onclick="myfunction()" /> <div id="word"> </div> </form> <center> LINGO </center> </body> </html> what i would really like to do is have a button that gets the word from the dictionary file that i have set up with php and mySQL, then when the word first displays, I want to show blanks first, however if I can't get it in a variable to manipulate it, i can do the rest... Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/#findComment-1042624 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Change xmlhttp.onreadystatechange=function(var gameWord) To xmlhttp.onreadystatechange=function() Change document.getElementById('word').innerHTML=xmlhttp.responseText; To gameWord = xmlhttp.responseText; Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/#findComment-1042629 Share on other sites More sharing options...
husslela03 Posted April 15, 2010 Author Share Posted April 15, 2010 Now nothing prints... Link to comment https://forums.phpfreaks.com/topic/198583-xml-response-text-into-a-variable/#findComment-1042633 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.