Jump to content

Storing code in value attribute of an input field


gwh

Recommended Posts

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.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.