placeholder = 'Type some text'; // The placeholder text
addEvent(textField, 'focus', function() {
if (this.value === placeholder) this.value = '';
});
addEvent(textField, 'blur', function() {
if (this.value === '') this.value = placeholder;
});
Thing is as I'm going to be creating quite a few forms with various different field names etc, I wanted to know the best way to implement this so that it would clear any field on first click but not the second (so it doesn't delete what the user has entered), rather than having to list out all of the placeholder text and field names.
I hope this makes sense. I may just be over complicating things!
Question
Axel
I've done a little searching and found some javascript that does sort of what I'm after.
Thing is as I'm going to be creating quite a few forms with various different field names etc, I wanted to know the best way to implement this so that it would clear any field on first click but not the second (so it doesn't delete what the user has entered), rather than having to list out all of the placeholder text and field names.
I hope this makes sense. I may just be over complicating things!
Many thanks :),
Alex
Link to comment
Share on other sites
10 answers to this question
Recommended Posts