Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:50:28+00:00 2026-06-06T00:50:28+00:00

In my code behind, I have – tbWhatIfBeginDate.Attributes.Add(onchange, checkDates( + tbWhatIfBeginDate.ClientID + , +

  • 0

In my code behind, I have –

tbWhatIfBeginDate.Attributes.Add("onchange", "checkDates(" + tbWhatIfBeginDate.ClientID + ", " + tbWhatIfEndDate.ClientID + ")");
tbWhatIfEndDate.Attributes.Add("onchange", "checkDates(" + tbWhatIfBeginDate.ClientID + ", " + tbWhatIfEndDate.ClientID + ")");

and here is my javascript function –

function checkDates(BeginDateId, EndDateId) {
    if (BeginDateId.value > EndDateId.value) {
        var beginDt = new Date(BeginDateId.value);
        var endDt = new Date(EndDateId.value);

        var newDt = new Date(endDt.getTime() - (24 * 60 * 60 * 1000));

        var y = newDt.getFullYear(),
        m = newDt.getMonth() + 1, // january is month 0 in javascript     
        d = newDt.getDate();

        BeginDateId.value = [pad(m), pad(d), y].join("/");
    }
}

when I run through Visual Studio 2010, it works.

When I deploy to my test server, I get an error message. “Object expected – Line:176,Char:1”

line 176 is –
input name=”ctl00$cpMain$tbWhatIfBeginDate” type=”text” value=”8/1/2012″ id=”ctl00_cpMain_tbWhatIfBeginDate” onchange=”checkDates (ctl00_cpMain_tbWhatIfBeginDate, ctl00_cpMain_tbWhatIfEndDate)” style=”width:70px;”

I don’t see an error.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:50:30+00:00Added an answer on June 6, 2026 at 12:50 am

    You are passing the id of HTML elements to the function, which are strings, but you pass it without quotes, as if it were a defined variable. In the onClick scope, there is no such variable ctl00_cpMain_tbWhatIfBeginDate already defined, so you’re getting a javascript error. That’s expected — you’ve not declared such a variable.

    In your function, you then immediately try to treat these arguments as objects, but again, you passed in undefined since the variables with the specified names didn’t exist. Nor should they! When you’re attempting to reference a DOM node by id, you have to use getElementById from the document object to “fetch” the related object. The ids, then, are just string.

    As such, you should pass those strings wrapped in quotes. To do this, you need to modify the two lines where you add the events:

    tbWhatIfBeginDate.Attributes.Add("onchange", "checkDates('" + tbWhatIfBeginDate.ClientID + "', '" + tbWhatIfEndDate.ClientID + "')");
    tbWhatIfEndDate.Attributes.Add("onchange", "checkDates('" + tbWhatIfBeginDate.ClientID + "', '" + tbWhatIfEndDate.ClientID + "')");
    

    That way, the string ids get passed to your function. Then, your function needs to be modified to get the DOM objects based on the passed ids:

    function checkDates(BeginDateId, EndDateId) {
        beginDate = document.getElementById(BeginDateId);
        endDate = document.getElementById(EndDateId);
        if (!beginDate || !endDate)
            return; // <--- add an error message here?
        if (beginDate.value > endDate.value) {
            var beginDt = new Date(beginDate.value);
            var endDt = new Date(endDate.value);
            // existing logic here
        }
    }
    

    Documentation

    • document.getElementById – https://developer.mozilla.org/en/DOM/document.getElementById
    • javascript functions – http://www.quirksmode.org/js/function.html
    • javascript variables – http://www.tizag.com/javascriptT/javascriptvariables.php
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the code behind I have a function that returns a List(Of SomeClass): rptRepeater.DataSource
I have the following code behind a button in Visual Studio 2010 private void
I have c# code behind my Excel-dna addin which is successfully downloading data from
I have no code behind and the above error keep prompting on INSERT. The
I have below code behind in c# if (Session[cmpDictionaryTitle]!= null) { downloadLinks.Text += @<li><a
In code-behind of an ASP.NET page I have this method: public string TestFunc() {
I have AutoEventWireup=true and in my code behind protected void Page_Init(object sender, EventArgs e)
I have an ASP.NET page with code-behind in VB.NET. On the ASPX page I
If I have pages having server-side code in code-behind, then I know that the
I have a Xaml file that does not have any code behind. I would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.