[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Parsed variable is UNDEFINED

Posted on 2006-03-21
3
Medium Priority
?
215 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:texaspete
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
mvan01 earned 360 total points
ID: 16246095
Hi TP,

In the function openCalendar() have you tried replacing

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

with

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

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

mvan
0
 

Author Comment

by:texaspete
ID: 16246386
SORTED!!! mvan your're a star!!!

Have some points!

0
 
LVL 11

Expert Comment

by:mvan01
ID: 16246736
Happy to help.  Thanks!

mvan
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question