Niths Niths - 1 year ago 46
HTML Question

Place holder is not working

Place holder is not working in IE-9,so I used the below code for place holder.

jQuery(function () {
debugger;
jQuery.support.placeholder = false;
test = document.createElement('input');
if ('placeholder' in test) jQuery.support.placeholder = true;
});
// This adds placeholder support to browsers that wouldn't otherwise support it.
$(function () {

if (!$.support.placeholder) {
var active = document.activeElement;
$(':text').focus(function () {
if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
$(this).val('').removeClass('hasPlaceholder');
}
}).blur(function () {
if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
$(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
}
});
$(':text').blur();
$(active).focus();
$('form:eq(0)').submit(function () {
$(':text.hasPlaceholder').val('');
});
}
});


When I am taking the value of test,it shows null.How can I get the details of all input tag?

Answer Source

I think this will help you

if ($.browser.msie) {
                    $("input").each(function () {
                        if (IsNull($(this).val()) && $(this).attr("placeholder") != "") {
                            $(this).val($(this).attr("placeholder")).addClass('hasPlaceHolder');
                            $(this).keypress(function () {
                                if ($(this).hasClass('hasPlaceHolder')) $(this).val("").removeClass('hasPlaceHolder');
                            });
                            $(this).blur(function () {
                                if ($(this).val() == "") $(this).val($(this).attr("placeholder")).addClass('hasPlaceHolder');
                            });
                        }
                    });
                }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download