I’m renewing question. For simplify situation I’ve this script in index.php file
<form name="f" action="index.php" method="post">
<input type="button" name="but" id="but" value="Retrieve">
<div id="div"></div>
<input type="submit" name="ok">
</form>
<script type="text/javascript">
document.getElementById("but").onclick = function(){
var http = false;
if (window.XMLHttpRequest){
http = new XMLHttpRequest();
} else {
http = new ActiveXObject("Microsoft.XMLHttp");
}
if (http){
http.open("POST","other.php",true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.onreadystatechange = function(){
if (http.status==200 && http.readyState==4){
document.getElementById("div").innerHTML = http.responseText;
}
};
http.send(null);
}
};
document.getElementById("y").onclick = function(){
alert("okaaay");
};
</script>
And have other.php file with the script below
<?php
echo "<input type='text' name='y' id='y'>";
?>
Ajax script works just nice, but my problem is that when this marked input element is retrieved in index.php page , with second JavaScript code I can’t manipulate it , please help , thanks 🙂
change the code so you set the “y” onclick after the response from the other.php comes back, like so:
otherwise you’re setting that event handler on an element that does not yet exist 🙂