gwh Posted March 25, 2010 Share Posted March 25, 2010 Hi everyone, I have the following input field in my form: <input id="firstname" name="firstname" type="text" value="First name" onfocus="if (this.value == 'First name') this.value=''" onblur="if (this.value == '') this.value='First name'" /> And the field is being validated by the following code: <?php if (ValidatedField('index_965','index_965')) { if ((strpos((",".ValidatedField("index_965","index_965").","), "," . "1" . ",") !== false || "1" == "")) { if (!(false)) { ?> <span style="color: red"> First name is required </span> <?php } } }?> Currently if the validation fails the error message is being output to a span element below the input field. I wanted to change this so that the error would be output in the value attribute of the input field so it would look something like this: <input id="firstname" name="firstname" type="text" value="<?php if($serverside) {echo "invalid";} else echo "First name"; ?>" onfocus="if (this.value == 'First name') this.value=''" onblur="if (this.value == '') this.value='First name'" /> But I'm not sure how to make it work. Would I store the validation code in the variable called $session like this: $session = <?php if (ValidatedField('index_965','index_965')) { if ((strpos((",".ValidatedField("index_965","index_965").","), "," . "1" . ",") !== false || "1" == "")) { if (!(false)) { ?> <span style="color: red"> First name is required </span> <?php } } }?> Appreciate any advice. Link to comment https://forums.phpfreaks.com/topic/196448-storing-code-in-value-attribute-of-an-input-field/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.