Link to home
Create AccountLog in
Avatar of texaspete
texaspete

asked on

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 )); };
  td2.appendChild(a);

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 )); };
  td2.appendChild(a);

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(sField.name);
      var newWin = window.open("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

Regards,

TP
ASKER CERTIFIED SOLUTION
Avatar of mvan01
mvan01
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of texaspete
texaspete

ASKER

SORTED!!! mvan your're a star!!!

Have some points!

Happy to help.  Thanks!

mvan