
Originally Posted by
JonParks
Thanks Erik! Working great, just one issue... on the page load the default text is not displayed. It only appears when I click in the field, is there a way to have the labels load with the page?
I guess you have not set a default value. In that case the input value is empty from start but then the value is inserted on blur.
On load the input should have the default value. If form is submitted with error and returned the input should have the returned value.
In case you are all new to php and have no idea how to get the default value from start, you can try this code in the page (no offense by the newbe comments):
Code:
Place the script anywhere before the input
<?php
$defaultvalue = 'Your Name'; // store a default value
// detect if form was submitted and use entered value or use the default value
if (isset($_POST['name'])){ // check if POST variable is set.
$namevalue = $_POST['name']; // if true, get value and store it
}
else { // if false, the page is first loaded
$namevalue = $defaultvalue; // then set it to the default value
}
?>
Now use the variable $namevalue to set the input value
<input id="name" name="name" type="text" value="<?php echo $namevalue; ?>"
onBlur="this.value=(this.value=='') ? 'Your Name' : this.value;"
onFocus="this.value=(this.value=='Your Name') ? '' : this.value;" />
If I guessed your settings right, .
Bookmarks