guttyguppy Posted September 5, 2008 Share Posted September 5, 2008 I'm trying to get a link on a page to insert a random word (presumably from some English dictionary) into a text field. I've written php to display a random word on a page whenever the page is refreshed, so I can probably build from that. I just don't know much about ajax or how to pull this off. Any help would be greatly appreciated, thanks! Quote Link to comment Share on other sites More sharing options...
barkermn01 Posted September 5, 2008 Share Posted September 5, 2008 Easy function GetXmlHttpObject(){ var xmlHttp=null; try{ xmlHttp=new XMLHttpRequest(); } catch (e){ //Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } return xmlHttp; } function getPage(url){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("Browser does not support HTTP Request"); return; } url=url+"?sid="+Math.random(); // fix to keep IE from cacheing the page xmlHttp.open("GET",url,true); xmlHttp.onreadystatechange=function() { if (xmlHttp.readyState == 4){ document.getElementById("").value = xmlHttp.responseText; // The ID of your Text box }else{ // Your Code to do when you dont have your page loaded so a nice laoding image works } } xmlHttp.send(null); } Then onClick of your button getPage('random.php'); Quote Link to comment Share on other sites More sharing options...
guttyguppy Posted September 6, 2008 Author Share Posted September 6, 2008 Thank you so much, it worked perfectly! 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.