Board Logo

cal2 is undefined error is thrown; when dynamically adding multiple calendar records.
gopdik - 3/19/2008 at 01:11 PM

I am calling the below javascript code to add multiple records on my JSP Page. One field is an enterable text field & the second one is the Tigra calendar object.

When clicking on the calendar icon; it says cal2 is undefined.
The reason being that when multiple records are added;
for all the rows, there is only one cal2 variable.

So please provide a proper solution, as to how shall I achieve this for multiple records.

function addItem(in_tbl_name)
{
var tbody = document.getElementById(in_tbl_name).getElementsByTagName("TBODY")[0];

var numberOfRows = tbody.rows.length;

rIndex = numberOfRows - 1;

// create row
var row = tbody.insertRow(rIndex);

var pettyCashItemUniqueID = itemUniqueID++;

// New Text Item to add.
var td3 = document.createElement("TD")
td3.innerHTML = "<INPUT TYPE="text" NAME=Amount_" + pettyCashItemUniqueID + " SIZE="13" MAXLENGTH="20" onblur="return checkAmount(this);" CLASS="input">";
row.appendChild(td3);

// New Text Item to add.
var td5 = document.createElement("TD")

td5.innerHTML = "<INPUT TYPE="text" NAME=ReceiptDate_" + pettyCashItemUniqueID + " readonly="readonly" SIZE="15" MAXLENGTH="20" CLASS="input"> <A HREF="javascript:cal2.popup();"> <IMG SRC="img/cal.gif" width="16" height="16" border="0" alt="Receipt Date"> </A>";
row.appendChild(td5);

var cal2 = new calendar2(document.forms['pettyCashClaim'].elements['ReceiptDate_' + pettyCashItemUniqueID]);
cal2.year_scroll = true;
cal2.time_comp = false;

if (tbody.rows[rIndex])
{
for (var i=rIndex; i<tbody.rows.length; i++)
{
tbody.rows.className = "r1"
}
}
}

Thanks & Regards,
Gopal D. Kalsekar


tigra - 3/19/2008 at 04:34 PM

you define var cal2 inside of the function then try to use it from the context of the document.
try window.cal2 = new calendar2(...) instead

there may be more problems. the calendar wasn't designed for the dynamic use like this, however I don't see any obvious reasons why it shouldn't work.


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/