Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get placeholder text in firefox and other browsers that don't support the html5 tag option?

This works in Chrome and any other browser that supports placeholder text in HTML5

<input id="name" name="name"  type="text" placeholder="Please enter your name..." required /> <br />

But, it doesn't work in 3.5 and earlier of Firefox, and obviously IE8, and possibly other browsers.

How do I achieve the same thing (preferably in HTML/CSS - if not I am open to suggestions), to support all the older browsers? If not every single browser, at least Firefox and IE.

Safari and Chrome already support it (or the latest versions anyway).

Thanks.

like image 650
marcamillion Avatar asked Aug 07 '10 07:08

marcamillion


People also ask

What is the tag to be used if we have to create an input element for text with the value this is my form element?

The <input> tag specifies an input field where the user can enter data. The <input> element is the most important form element.

What is placeholder text in website?

Placeholder text is the label for possible content in a text box. It can normally be found when there are prompts to fill out a form. It's the hint that tells you 'Last name' or the format with which to enter your birthdate or phone number.

How does input work HTML?

The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide variety of types of input data and control widgets are available, depending on the device and user agent.


2 Answers

One day I'll get around to properly documenting this, but see this example: http://dorward.me.uk/tmp/label-work/example.html

In short — position a <label> under a transparent <input> using <div> to provide background colour and borders.

Then use JS to determine if the label should be visible or not based on focusing.

Apply different styles when JS is not available to position the label beside the element instead.

Unlike using the value, this doesn't render the content inaccessible to devices which only display the focused content (e.g. screen readers), and also works for inputs of the password type.

like image 77
Quentin Avatar answered Oct 22 '22 16:10

Quentin


I use this one: https://github.com/danbentley/placeholder
Lightweight and simple jQuery plugin.

like image 20
Florian Avatar answered Oct 22 '22 17:10

Florian