I have several places on my page where I need to display either values from the database or input values from a form that are used in more than one place.
The code below works fine if I comment out the "document.getElementById" statement. The array is created and the alert works, but I can't get the value from the array to display in the div.
I'm just learning how to do this. What am I missing?
mysql_connect("mydbip", "username", "password") or
die("Could not connect: " . mysql_error());
$result = mysql_query("SELECT * FROM sometable WHERE id='1'");
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$myarr = json_encode($row);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
var ar = new Object();
ar= <?php echo $myarr;?>;
if(ar["variable1"] > 0)
document.getElementById("ar1").innerHTML = ar["variable1"];