You will see in the code that first_name is populated by two different methods. 1) JQuery will populate html first_name with barney and 2) Php will populate the $first_name with fred.
barney displays on the rendered html. When I inspect the field with Developer Tools, I see the value as fred.
At what point does the PHP field match the html? When the form posts?
[php]
<SCRIPT LANGUAGE="javascript" >
$(window).load(function(){
$("#first_name").val("barney");
});
</SCRIPT>
</head>
<body>
<?php
$first_name = "fred";
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
Name: <input type="text" id="first_name" name="first_name" value="<?php echo $first_name;?>">
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
[/php]