Placeholder for my textbox in below format is not working for Internet Explorer. Is there anyway to display placeholder for TextBox in Internet Explorer?
<asp:TextBox id="email" runat="server" width="300" placeholder="Your email" />
Is there any simple way just by using any JavaScript. I am not interested to make it complicated using jQuery.
You can imitate this using pure JavaScript:
This will do nothing if the browser is already supporting the
placeholderattribute, and in case it’s not supported (e.g. the browser is IE) it will add very similar functionality – text shown by default that disappear on focus and appears again if user didn’t type anything.Live test case.
Bug Fixes
Nov 6, 2012: Previous code failed to detect when browser didn’t have native support for placeholder. Using code found in this other post it’s now fixed. Affected browsers: IE7 and IE8, maybe others as well. Also added debug support to help debug future problems.
Jan 30, 2013:
Adding support for password input as well. Since IE8 and below won’t allow dynamic change of input type, the code is replacing the password input with text input as long as there is no password typed, thus the placeholder text will be visible.
Fixed bug that caused the placeholder value to be sent where empty value should be sent to the server when the form associated with the input is being submitted. To achieve this, code is attached to the form submit event and clear the value if needed.
Jan 24, 2014: adding support for
<textarea>elements.