1. You haven't used responseText to allow the Javascript to display the callback text
2. if that is one file all the html above the PHP code will also be sent in the callback.
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
<?php if(isset($_POST['ajax'])) { $text = htmlentities(stripslashes($_POST['ajax'])); print " <br>{$text}"; } else { print <<<EOD <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title>Untitled Document</title> <script type="text/javascript"> function changename() { var ajaxobject, ajaxdisplay = document.getElementById('ajaxDiv'), ajaxtextarea = document.getElementById('ajaxtext'); if(window.XMLHttpRequest) { ajaxobject = new XMLHttpRequest(); } else if(window.ActiveXObject) { ajaxobject = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert("Your browser does not support Ajax!"); } ajaxobject.onreadystatechange=function() { if(ajaxobject.readyState == 4 && ajaxobject.status == 200) { ajaxtextarea.innerHTML = ajaxobject.responseText; } } ajaxobject.open("POST","ajax.php",true); ajaxobject.setRequestHeader("Content-type","application/x-www-form-urlencoded"); ajaxobject.send("ajax="+ajaxdisplay.innerHTML); } </script> </head> <body> <div id="ajaxDiv">My Div Text</div><br> <textarea id="ajaxtext"></textarea> <input name="Submit" id="Submit" value="Submit" onclick="changename();" type="button"> </body> </html> EOD; } ?>
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
You can not use this as it will run the function before the onload
Code:
window.onload = changename();
you have to use this
Code:
window.onload = changename;
or this
Code:
window.onload = function(){changename();};
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
If I understand correctly you want the id name to be stored in a var and then use it in the document.getElementById function.
Code:
var myvar = 'ajaxtext',
res = http.responseText;
document.getElementById(myvar).innerHTML = res;
// OR you can just do this
var myvar = document.getElementById('ajaxtext'),
res = http.responseText;
myvar.innerHTML = res;
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
Oh you want to send the word 'ajaxtext' over to the PHP code that's why you are setting it as a variable ok just do this.
Code:
http.send('myvar='+myvar);
And in PHP you would use this.
PHP Code:
$myphpvar = $_POST['myvar'];
__________________
Official BinPress hand picked coder.
For anyone worried about SQL injection go have a look at my small yet powerful script here.
Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
I am 1 of 65,608 people to get a Pebble Watch :P
when ever i typed somthing and submit it didnt post anything what is wrong with my ajax script do i need to change getElementById to some form.element ?