Solved

Looking to solve input placeholder IE 8 compatibility issue.

Posted on 2014-07-24
2
2,299 Views
Last Modified: 2014-07-24
I have the following implemented and it's not quite working correctly. And you can only see my solution in IE 8 as it checks if placeholder is compatible because IE 8 doesn't have support for the "placeholder" attribute and I'm trying to figure out a way to solve the issue so that it works in IE 8. You can see what I've started but the last remaining piece is when you focus on the password field it should change the input type to "password" and if you unfocus out of the field with no entry it should default back to "text" input type only if the val = "" or the user didn't actually enter anything. If there's a more streamlined way of what I've already done please share as well. Thx


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

<script>
jQuery(function() {
   jQuery.support.placeholder = false;
   test = document.createElement('input');
   if('placeholder' in test) jQuery.support.placeholder = true;
});

$(function() {
   if(!$.support.placeholder) {

      var active = document.activeElement;

      var pass = $('<input id="password" class="textbox" name="password" placeholder="Password" type="text">');
      $("#password").replaceWith(pass);

      $(':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');
         }
      });

      $(document).on('focus click', '#password', function () {
         var pass = $('<input id="password" class="textbox" name="password" placeholder="Password" type="password">');
         $("#password").replaceWith(pass);
      });

   }

   $(active).focus();
   $(':text').blur();

   $('form:eq(0)').submit(function () {
      $(':text.hasPlaceholder').val('');
   });
});
</script>

<style>
   input {width: 150px;}
</style>

</head>
<body>
   <input id="login_id" class="textbox" name="login_id" placeholder="Username" type="text" /><br>
   <input id="password" class="textbox" name="password" placeholder="Password" type="password">
</body>
</html>

Open in new window

0
Comment
Question by:brihol44
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
ID: 40217711
0
 

Author Comment

by:brihol44
ID: 40217888
Because I didn't know about it. Thx!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AJAX ModalPopupExtender will Not Hide in Asp.net 1 32
How to calculate height of a text using jquery 3 40
Jquery driving me nuts... 14 27
javascript and jquery question 4 21
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question