Click here to Skip to main content
15,850,547 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello My Dear Friends,
I am trying to use placeholder attribute in my website.

i am using this script for IE
it works but only for input text.

JavaScript
<script type="text/javascript">
    $(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();
           
           
            
        }
    });
</script>



I want placeholder for password & textarea also....
Please Help...!
Posted
Updated 19-Oct-11 7:10am
v2

1 solution

You say "I want"… Hm. You just want way to much from old good goofy IE. See: http://www.w3schools.com/html5/att_input_placeholder.asp[^].

—SA
 
Share this answer
 
Comments
raghukandru 21-Mar-13 6:51am    
<script type="text/javascript">
if(navigator.userAgent.indexOf("MSIE") > 0 ){
$(function() {
var input = document.createElement("input");
if(('placeholder' in input)==false) {
$('[placeholder]').focus(function() {
var i = $(this);
if(i.val() == i.attr('placeholder')) {
i.val('').removeClass('placeholder');
if(i.hasClass('password')) {
i.removeClass('password');
this.type='password';
}
}
}).blur(function() {
var i = $(this);
if(i.val() == '' || i.val() == i.attr('placeholder')) {
if(this.type=='password') {
i.addClass('password');
this.type='text';
}
i.addClass('placeholder').val(i.attr('placeholder'));
}
}).blur().parents('form').submit(function() {
$(this).find('[placeholder]').each(function() {
var i = $(this);
if(i.val() == i.attr('placeholder'))
i.val('');
})
});
}
});
}
</script>
raghukandru 21-Mar-13 6:52am    
i got the same problem but i use the above code to solve this issue

add the below style tag to your .css file

.placeholder {
color: #aaa;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900