Ideal "replacement" for the placeholder

Asked

Viewed 180 times

1

I’m in the final phase of a project! And now I’m doing the analysis as performance tests and structuring errors! One of the errors found is the placeholder of inputs and textarea. What I can use in place of the placeholder is that of preferably not error at validation time?

inserir a descrição da imagem aqui

  • What would this validation error be? Is it really necessary to remove the property? It is the most suitable for your proposed goal, semantically speaking.

1 answer

2


Change your document to HTML5 by simply changing the doctype at the beginning of the file to <!doctype html>.

<!doctype html>
<html>
  <!-- head -->
  <body>
     <input type='text' name='foo' placeholder='foo'>
  </body>
</html>

If this is not possible in your project, you can then choose to use Javascript to create the same effect as the attribute placeholder:

<input type='text' value='foo'
       onfocus="if (this.value === 'foo') {this.value = '';}"
       onblur="if (this.value === '') {this.value = 'foo';}">

The second option gives a little more work, it is not simply checking if the field value is "foo" (which was just an example). In that case, use a plugin that this treatment may be the best solution, for example the Placeholder.js.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.