{"id":376,"date":"2014-08-17T15:12:58","date_gmt":"2014-08-17T14:12:58","guid":{"rendered":"http:\/\/www.cotsweb.com\/blog\/?p=376"},"modified":"2014-08-17T15:12:58","modified_gmt":"2014-08-17T14:12:58","slug":"adding-placeholders-to-ie8-ie9-using-jquery","status":"publish","type":"post","link":"https:\/\/www.cotsweb.com\/blog\/adding-placeholders-to-ie8-ie9-using-jquery-376.html","title":{"rendered":"Adding placeholders to IE8 &#038; IE9 using jQuery"},"content":{"rendered":"<p>The placeholder attribute on the input statement is a useful way of providing prompts to the user without cluttering up the screen, it is well supported by all modern browsers but sadly not by versions of Internet Explorer before IE10.\u00a0 There is<a title=\"jQuery Watermark plugin on google code\" href=\"https:\/\/code.google.com\/p\/jquery-watermark\/\"> a good jQuery plugin called watermark <\/a>which solves the problem but you need to apply it to the\u00a0 required fields, they suggest something like.<\/p>\n<p><code class=\"preserve-code-formatting\">$( &#039;#inputId&#039; ).watermark( &#039;Required information&#039; );<\/code><\/p>\n<p>That is fine but I don&#8217;t really want to separately to each field, particularly if I have already populated the placeholder for each field.\u00a0 So being lazy I have written a little bit of jQuery which takes the existing placeholder for each field and adds it as a watermark.<\/p>\n<p><pre><code class=\"preserve-code-formatting\">\n&lt;script type=&quot;text\/javascript&quot; src=&quot;js\/jquery.min.js&quot;&gt;&lt;\/script&gt;\n&lt;script type=&quot;text\/javascript&quot; src=&quot;js\/jquery.watermark.min.js&quot;&gt;&lt;\/script&gt;\n\n&lt;script type=&quot;text\/javascript&quot;&gt;\n&nbsp;&nbsp; $(document).ready(function () {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \/*\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* Set watermarks on input fields; IE8 &amp; IE9 don&#039;t support placeholders\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* This routine extracts the placeholder text from the HTML input statements and \n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;passes it to the jQuery watermark plugin\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;* so we don&#039;t have to separately maintain the watermark text\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*\/\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(&#039;[placeholder]&#039;).each(function () {\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; var placeholderText = $(this).attr(&#039;placeholder&#039;);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $(this).watermark(placeholderText);\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; });\n&nbsp;&nbsp; });\n&lt;\/script&gt;\n<\/code><\/pre><\/p>\n<p>Obviously this requires that you have included jQuery and the jQuery watermark plugin earlier in your code as I have in the example but now every input field that I add a placeholder to<br \/>\n<code class=\"preserve-code-formatting\">&lt;input type=&quot;text&quot; placeholder=&quot;Put some text in here&quot; name=&quot;textField&quot; \/&gt;<\/code><br \/>\nwill display that placeholder text whether the user is running the latest version of Chrome or an antique version of Internet Explorer.<\/p>\n<p>I hope you find this useful.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>The placeholder attribute on the input statement is a useful way of providing prompts to the user without cluttering up the screen, it is well supported by all modern browsers but sadly not by versions of Internet Explorer before IE10.\u00a0 There is a good jQuery plugin called watermark which solves the problem but you need [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[22,18],"tags":[102,135,134,133],"_links":{"self":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts\/376"}],"collection":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/comments?post=376"}],"version-history":[{"count":10,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts\/376\/revisions"}],"predecessor-version":[{"id":387,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/posts\/376\/revisions\/387"}],"wp:attachment":[{"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/media?parent=376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/categories?post=376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cotsweb.com\/blog\/wp-json\/wp\/v2\/tags?post=376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}