Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I am using the following code for my need:
I want to allow user to select either only Current date or one previous date..

JavaScript
function checkdate() {
           
            var dt = document.getElementById("TextBox1").value;


            var currdt = new Date();
            if (dt != null) {
                var myDate_array = dt.split("/");



                var enteredDate1 = new Date(myDate_array[2], parseInt(myDate_array[1]) - 1, parseInt(myDate_array[0]) + 2);


                var today1 = new Date();
                if (enteredDate1 < today1) {
                    document.getElementById("TextBox1").value = "dd/MM/yyyy";
                    alert("Case File date must be greater than current date");
                    return false;
                }

                var enteredDate = new Date(myDate_array[2], parseInt(myDate_array[1]) - 1, myDate_array[0]);
                var today = new Date();
                if (enteredDate > today) {
                    document.getElementById("TextBox1").value = "dd/MM/yyyy";
                    alert("Case File date must be less than current date");
                    return false;
                }

            }


        }



HTML CODE:

ASP.NET
<asp:TextBox ID="TextBox1" runat="server" onfocus="if(this.value=='dd/mm/yyyy') this.value='';"
            onblur="if(this.value=='') this.value='dd/mm/yyyy';" Text="dd/mm/yyyy" onchange="javascript:checkdate();"></asp:TextBox>

this code works good in my new project..but when i implement this code in my running project's content page which have master page it does not work ,at runtime,in Inspect Element side I m getting error like:

ReferenceError: doStuff is not defined
TypeError: document.getElementById(...) is null
TypeError: document.getElementById(...) is null


plz do suggest what i need else to make this code work properly in running project ..
Posted
Updated 24-Feb-19 18:49pm
v3
Comments
You can debug the code by adding debugger; anywhere inside the code.
So, debug and check on which line it is throwing Exception.

1 solution

use this

C#
var dt = document.getElementById('<%=TextBox1.ClientID%>');
 
Share this answer
 
Comments
rahulDer 30-Jan-14 0:57am    
thank you KARTHIK..
but still this is giving same error in inspect element side :(
Karthik_Mahalingam 30-Jan-14 1:14am    
what is doStuff ?
rahulDer 30-Jan-14 1:20am    
that I also dont know..is it any type of property in javascript ?
Karthik_Mahalingam 30-Jan-14 1:28am    
find this text "dostuff". in you aspx file or javascript and reply.
might be some unwanted code..
rahulDer 30-Jan-14 1:36am    
Now "Dostuff" eroor is gone but
TypeError: document.getElementById(...) is null
is continuing ..

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