Jump to content

Avocado

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Avocado's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Cool thanks gamblor1 I appreciate your help
  2. Hi, I can't figure out what my code is missing. The text input from the 'name' id isn't submitting to the php page, Here is the html form: <body> <form> Enter name: <input type="text" id="name"> <input type="button" value="Send" onclick="loadAJAX('phppage.php')"> </form> <div id="display"> </div> </body> This is the AJAX code: <script type="text/javascript"> function loadAJAX(url) { var params = "name=name" if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET",url,false); //Send the proper header information along with the request xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.setRequestHeader("Content-length", params.length); xmlhttp.setRequestHeader("Connection", "close"); xmlhttp.onreadystatechange = function() {//Call a function when the state changes. if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { alert(xmlhttp.responseText); } } xmlhttp.send(params); document.getElementById('display').innerHTML=xmlhttp.responseText; } </script> This is the PHP code: <html> <body> Hi <?php echo $_POST["name"];?> </body> </html> The "Hi" displays in the 'display' div, but the 'name' form data does not. I'm not sure what I'm mising. *Also about the parameters, I read a tutorial saying to put name=value&name=value for the parameters. But doesn't the input 'id' contain the value to submit to the php page? So what would I put for the value? Thanks
  3. My html form: <body> <form> <p>Enter a sentence:</p> <textarea rows="3" cols="20" name="nameoftextarea"> </textarea> <input type="button" value="Send Sentence" onclick="getServerText()"> </form> <div id="myPageElement"> Sentence will show here </div> </body> getServerText is the function for sending the XMLHTTPRequest object. <head> <script Language="JavaScript"> function getXMLHTTPRequest() { try { req = new XMLHttpRequest(); } catch(err1) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (err2) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (err3) { req = false; } } } return req; } var http = getXMLHTTPRequest(); function getServerText() { var myurl = 'phppage.php'; myRand = parseInt(Math.random()*999999999999999); var modurl = myurl+"?rand="+myRand; http.open("GET", modurl, true); http.onreadystatechange = useHttpResponse; http.send(null); } function useHttpResponse() { if (http.readyState == 4) { if(http.status == 200) { var mytext = http.responseText; document.getElementById('myPageElement').innerHTML = mytext; } } else { document. getElementById('myPageElement').innerHTML = ""; } } </script> </head> The the $_GET["nameoftextarea"] on the php page doesn't display in <div> but the "Hi" does <html> <body> Hi <?php echo $_GET["nameoftextarea"];?> </body> </html> I just started php and I don't see where the error is, thanks.
  4. Hi Ferdi I am new too
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.