Forum Moderators: open

Message Too Old, No Replies

Help with InnerHTML

Trying to format a PHP return that will be handled by client-side eval

         

kellycline

3:34 am on Feb 15, 2010 (gmt 0)

10+ Year Member



I have not been able to figure out how to format the PHP in order to have a string that eval can use to manage innerHTML. It appears that the PHP never returns to the html (I set an alert at the return and it didn't hit). I suspect that I am having a PHP error, but I do not know how to see it. I am new, not to programming, but to PHP and Ajax.

Thank you --

This is the html:

<html>
<head>
<title>Hello Ajax version 3</title>
<style type='text/css'>
* { font-family: Tahoma, Arial, sans-serif; }
#helloTitle{ color: #48f; font-size: 1.5em; }
</style>
<script type='text/javascript' src='prototype.js'> </script>
<script type='text/javascript'>
window.onload=function(){
$('helloBtn').onclick = function() {
var name = ?('helloTxt').value;
new Ajax.Request(
"hello3.php?name="+encodeURI(name),
{
method:"get",
onComplete:function(xhr){eval( xhr.responseText );}
}
);
};
};
</script>
</head>
<body>
<div id='helloTitle'>
<h1>Hello, stranger</h1>
</div>
<p>Please introduce yourself by entering your name in the box below</p>
<input type='text' size='24' id='helloTxt'></input>
&nbsp;
<button id='helloBtn'>Submit</button>
</body>
</html>

and this is the PHP

<?php
$name = $_GET['name'];
?>
document.getElementById('helloTitle').innerHTML = "<h1>Hello, <b><i><?php print $name
?></i></b></h1>";

Fotiman

3:10 pm on Feb 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




var name = ?('helloTxt').value;


I am guessing that your ? is supposed to be a $. Also, instead of encodeURI(name), you probably want encodeURIComponent(name). Also, instead of "onComplete", you probably want to define "onSuccess".

kellycline

6:25 pm on Feb 16, 2010 (gmt 0)

10+ Year Member



You are exactly correct! I don't know how many times I looked right past that ? and missed that it should be $.

Thank you.