user2242044
user2242044

Reputation: 9233

Prepopulating form field to meet required condition

I have a form that in some situations will have a pre populated value. To do this, I am using placeholder. If the placeholder value is not blank, I would like this to meet the required condition. Do I need a Javascript method or am I forgetting something simple?

<html>
  <body>
    <form action="demo_form.asp">
      Username: <input type="text" name="usrname" placeholder="username" required>
      <input type="submit">
    </form>
  </body>
</html>

Upvotes: 0

Views: 18

Answers (1)

Anubhab
Anubhab

Reputation: 741

placeholder value is not blank, I would like this to meet the required condition

Placeholder text is just displayed when you value is blank. Your required condition will be met if your 'value' is blank.

<input type="text" name="usrname" placeholder="username" value="Pre populated Value" required/>

This should meet your required condition. As-is no JS is needed.

The above is of the assumption that placeholder is set by you. If you want placeholder to act as your 'value' attribute, yes you would need javascript.

Upvotes: 1

Related Questions