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. Quote Link to comment 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; Quote Link to comment 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... Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Show me the code. Quote Link to comment 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... Quote Link to comment 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; Quote Link to comment Share on other sites More sharing options...
husslela03 Posted April 15, 2010 Author Share Posted April 15, 2010 Now nothing prints... 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.