How to enable placeholder in Internet Explorer 8 and 9

Hi guys! In this tutorial I will explain how you can enable placeholder in Internet Explorer 8 and 9. As you might know, Internet Explorer 7, 8, 9 doesn't support placeholder in forms.

I have created a sample jquery function for my project, that can enable placeholder in Internet Explorer 7, 8, 9:

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0)
{
jQuery("#input").attr("value","Search for");
jQuery("#input").click(function()
{
jQuery("#input").val("");
});
}

This code will check the type of browser:

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");

if (msie > 0)
{

 

}

Next, this code will add a sample value in my input field:

jQuery("#input").attr("value","Search for");

When users will click on the input, this code will empty the input field:

jQuery("#input").click(function()
{

jQuery("#input").val("");

});









Leave a Comment