Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 540
Nithin Viswanathan Avatar asked Aug 28 '13 11:08

Nithin Viswanathan


1 Answers

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');
                            });
                        }
                    });
                }
like image 98
user2156088 Avatar answered Sep 23 '22 02:09

user2156088