Parsed variable is UNDEFINED

Hi there,

I've got some javascript that creates a button dynamically on the page. This button is used to open a calendar popup. Each time a new button is added a counter is appended to the element name to make it unique. e.g. escalation_date then escalation_date2, escalation_date3, escalation_date4 etc...

The following code creates the button fine but hard codes the second element name (document.add.escalation_date2 ) when calling openCalendar

  var a = document.createElement('a');
  a.innerHTML = '<IMG src="/include/images/calendar.gif" border=0 alt="Select Date">';
  a.href = 'javascript:void(0);' ;
  a.onclick = function () { return (openCalendar("add", document.add.escalation_date2 )); };

This works fine but I don't want to hard code the element name.

Here what i'm trying  .......

  var a = document.createElement('a');
  var element = ("document.add.escalation_date" + (row_no))
  a.innerHTML = '<IMG src="/include/images/calendar.gif" border=0 alt="Select Date">';
  a.href = 'javascript:void(0);' ;
  a.onclick = function () { return (openCalendar("add", element )); };

the var 'element' does hold the correct element name but when its passed to openCalendar (which creates the querystring) it is undefined.

here is ths openCalendar function

function openCalendar(iForm, sField)
      var queryString;
      queryString  = '?Date=' + escape(sField.value);
      queryString += '&FormName=' + escape(iForm);
      queryString += '&DateFld=' + escape(;
      var newWin ="calendar.asp" + queryString, "calwin", "dependent=yes,directories=no,height=205,width=220,location=no,menubar=no,personalbar=no,resizable=no,scrollbars=no,status=no,toolbar=no,top=400,left=400");
      return false;

This is the Querystring created:             /calendar.asp?Date=undefined&FormName=add&DateFld=undefined

Any help greately appriciated


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi TP,

In the function openCalendar() have you tried replacing

     queryString += '&DateFld=' + escape(;


     queryString += '&DateFld=' + escape(sField);

Just treat that variable as a string variable, because you're building a string.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
texaspeteAuthor Commented:
SORTED!!! mvan your're a star!!!

Have some points!

Happy to help.  Thanks!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.