PDA

View Full Version : Odd innerHTML Behaviour



punk0mi
17 Mar 2010, 12:13 PM
Hello all,

Just ran into an odd issue using innerHTML. Take a look at the code below in PHP:



$result = mysql_query(...mysql query...);
$error = mysql_error();
$curtime = date("h:i:s:u");
if(!$result){
//IF QUERY = FALSE then set STATUS = ERROR
$status = $curtime.' - <font color="#ff0000"><b>ERROR:</b></font> '.$error;
//...call function and pass $status...
}else{
//If QUERY = TRUE then set STATUS = SUCCESS
$status = $curtime.' - <font color="#00ff00"><b>SUCCESS:</b></font> New User Created! '.$first.' '.$last.' added to the database!';
//...call function and pass $status...
}


The $status var is passed to a JavaScript innerHTML that looks like this:


parent.document.getElementById("status").innerHTML="'.$status.'";

but it doesn't publish. However, if I remove the HTML from the $status var in the PHP it will publish. I have echo'd the variable outside of the JavaScript, and it displays properly when processed as regular HTML.

Is there something I am missing or not passing correctly? All suggestions welcome...

punk0mi
17 Mar 2010, 02:05 PM
Just solved the issue...was using double quotes when it should have been single quotes...duh.

It should look like this:



$status = $curtime.' - <font color=\'#ff0000\'><b>ERROR:</b></font> '.$error;


and not like this:


$status = $curtime.' - <font color="#ff0000"><b>ERROR:</b></font> '.$error;