Hi,
I am really sorry to insist but, this is not the right solution.
As I said, using such trick will be very complicated for the javascript. Using the "placeholder" attribute will be easier and could be easily compatible with old browser.
By default, the placeholder attribute is compatible with:
* Firefox 4.0+
* Opera 11.01+
* Chrome 3.0+
* Safari 3.0+
* Internet Explorer 10+
For old version, there are some script, like a little jQuery script:
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
}
})
});
And a little CSS
.placeholder { color:#999; }
The script support all cases (focus, blur and form submission). So there is no more development to do.
About the attribute, you can set the placeholder attribute like other attributes (like the class or the javascript events).
So, something like:
$js = 'placeholder="'.$value.'"';
should work good.
Best regards,