Click here to Skip to main content
15,904,297 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Below is my code for placing the place holder text in textbox as mm/dd/yyyy it is working in chrome browser but the place holder text and the date picker which is working in chrome is not supporting in firefox and Internet Explorer


<script>
        $('input[type="date"], input[type="datetime"], input[type="datetime-local"], input[type="month"], input[type="time"], input[type="week"]').each(function () {
            var el = this, type = $(el).attr('type');
            if ($(el).val() == '') $(el).attr('type', 'text');
            $(el).focus(function () {
                $(el).attr('type', type);
                el.click();
            });
            $(el).blur(function () {
                if ($(el).val() == '') $(el).attr('type', 'text');
            });
        });

    </script>

<asp:TextBox ID="txtFromDate" Width="113px" runat="server" type="date" placeholder="Date">


What I have tried:

My requirement is to have a place holder text as mm/dd/yyyy in textbox and while typing month mm should disapper and while typing date dd should disappear similarly for yyyy how can i do this
Posted
Updated 2-May-17 21:56pm

1 solution

Correct The types:

type="date",
type="datetime-local",
type="month", type="time",
type="week'

Are not supported in FireFox, IE and Chrome below version 20.
To be able to use date type in all browser you can check using modernizer and if not supported you can fall back to use javascript to show the datepickerr.

<script>
    $(function(){           
        if (!Modernizr.inputtypes.date) {
            $('input[type=date]').datepicker({
                  dateFormat : 'yy-mm-dd'
                }
             );
        }
    });
</script>



Other solution will be to use bootstrap datetime picker, but unfortunately you have to change this date/datetime box manually. p.s. bootstrap datetime picker works for FireFox but IE is still a problem.
 
Share this answer
 
v2

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