Q:

Getting JS runtime error ONLY when debugging in VS 2010

For some reason when I am trying to debug my site in VS I get the error 

JavaScript runtime error: Unable to set property 'value' of undefined
  or null reference

when using a date picker. I can hit continue and everything works perfectly fine. If I run the site without debugging everything works fine, the exact same code running in production works fine so why is VS complaining about this only when I debug?
  function SetDate(formName, id, newDate, postBack) {
      var theform = document.getElementById(formName);
      popUp.close();
      theform.elements[id].value = newDate;

      if (id = "txtDate3") {
          theform.elements['txtDate4'].value = newDate
      }

      if (postBack) __doPostBack(id, '');
  } 

A:

 if (id = "txtDate3")

assignment is improper here, use conditional
if (id == "txtDate3")

or 
if (id === "txtDate3")

