s_h
s_h

Reputation: 1496

Delete default value of an input text on button submit

I need to know what I can do in order to delete default value of an input text if user do not fill the field with information. Right now my form display "eg: Ipod, Iphone" when search bar displays. Code example:

<input type="text" value="eg: Ipod, Iphone" name="Product" id="Product"
onblur="if (this.value == '') {this.value = 'eg: Ipod, Iphone';}"
onfocus="if (this.value == 'eg: Ipod, Iphone') {this.value = '';}" />
<button class="submit" title="Post" type="submit"><span>Submit</span></button>

my idea is to display that information - eg: Ipod, Iphone - but if someone press submit with no new information in that textbox the information passed change to Ipod or Iphone and not eg: Ipod, Iphone all together. thanks in advance.

aaaa

Upvotes: 1

Views: 1107

Answers (1)

Robert Fricke
Robert Fricke

Reputation: 3643

As said in the comments, use html attribute placeholder:

<input type="text" placeholder="eg: Ipod, Iphone" /> 

For the older browsers that does not support this attribute there are some jquery plugins that can handle this. We use jquery-watermark for that. It only requires you to set the class="watermark" on the input and include the script file.

Upvotes: 3

Related Questions