Page 1 of 1
Placeholder doubt
Posted: Thu Nov 08, 2012 11:27 am
by Fidbeck
placeholder can be used with input fields, nothing wrong with that
but for example when I click in the field the placeholder text only disappears when I start writing. How to make it disappear when I hover over it.
Re: Placeholder doubt
Posted: Thu Nov 08, 2012 3:55 pm
by ExtremeGaming
If you mean when clicked, try:
<input type="text" placeholder="Enter Message..." onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter Message...'" />
If you really mean hover, try:
<input type="text" placeholder="Enter Message..." onmouseover="this.placeholder = ''" onmouseout="this.placeholder = 'Enter Message...'" />
Re: Placeholder doubt
Posted: Fri Nov 09, 2012 3:33 am
by Helx
Moved to HTML section.
Question to ExtremeGaming; would I be able to use that, but with value?
Because IE simply refuses to use PlaceHolder.
Re: Placeholder doubt
Posted: Fri Nov 09, 2012 9:38 am
by Fidbeck
Extremegaming that would make it disappear when I click on the field to start writing righr?
Re: Placeholder doubt
Posted: Fri Nov 09, 2012 6:17 pm
by ExtremeGaming
Helx wrote:
Question to ExtremeGaming; would I be able to use that, but with value?
Because IE simply refuses to use PlaceHolder.
Yes just change this.placeholder to this.value
However, you will need to remove the onblur because it will submit whatever you are setting the default value to, regardless of what you enter.
Fidbeck wrote:
Extremegaming that would make it disappear when I click on the field to start writing righr?
Yes once you click on the input field it will disappear.
Re: Placeholder doubt
Posted: Sat Nov 10, 2012 9:58 pm
by jacek
The normal way to do this is with a bit of JavaScript.
var input = document.getElementById('the_id');
input.addEventListener('focus', function(event){
if (this.value == ''){
this.value = 'Enter Message...';
}
});
input.addEventListener('blur', function(event){
if (this.value = 'Enter Message...'){
this.value = '';
}
});
Re: Placeholder doubt
Posted: Sat Nov 10, 2012 10:24 pm
by ExtremeGaming
And in case the user has javascript disabled you can always put it in a <noscript>
Re: Placeholder doubt
Posted: Sun Nov 11, 2012 4:26 pm
by Fidbeck
@ExtremeGaming
Even though I said click and hover I meant click
@Jacek
Your suggestion worked out too but ExtremeGaming's one is a bit more condensed.
Thanks for the answers
Re: Placeholder doubt
Posted: Sat Nov 17, 2012 12:15 am
by jacek
Fidbeck wrote:@Jacek
Your suggestion worked out too but ExtremeGaming's one is a bit more condensed.
The onAction attributes are no longer valid HTML
Re: Placeholder doubt
Posted: Sat Nov 17, 2012 9:31 am
by Fidbeck
I'm not using onAction, i'm using onfocus and onblur
kidding
itsnot? :S
Then I guess I have to change it :S