Dynamically declare objects in javascript

S

Secondpost

I need to use a calender object with a dynamic form i.e. when a new
row of fields is created using Javascript a calender button appears
aswell. The problem is if I need to declare the following code for the
calendar script to work:
var cal6 = new calendar1(document.forms['formname'].elements['fieldname']);
cal6.year_scroll = true;
cal6.time_comp = false;

where the # 6 will change as the user adds a new field (by clicking a
button).

My problem is that the code doesn't seem to execute during run-time.
If I add the code to the include file after the field is created it
still doesn't recognise that the calendar objects exists. Can anyone
help??
 
M

Mike Jones

How about using an array:

var cal = new Array();

function someFunction(index) {
cal[index] = new calendar1(etc...)
cal[index].year_scroll = true
}
 
S

Secondpost

The script I've put into the head is :

<script language="Javascript">
var calnew = new Array();

function myfun(index){
calnew[index] = new calendar1(document.forms['myform'].elements['txtTaskStartDate1']);
calnew[index].year_scroll = true;
calnew[index].time_comp = false;
};
</script>

Then I have a button on the page that onClick ="return
btnNew_onclick('People')"
where btnNew_onclick('People') calls a function in an include file (to
create the new fields) the last line of the function being
myfun(temp); where temp is the number of the object eg cal7. The field
is created along with the calender button with the correct hyperlink
but when this is clicked an error cal7 is undefined occurs.

What do you think I'm doing wrong??
Thanks.

How about using an array:

var cal = new Array();

function someFunction(index) {
cal[index] = new calendar1(etc...)
cal[index].year_scroll = true
}

I need to use a calender object with a dynamic form i.e. when a new
row of fields is created using Javascript a calender button appears
aswell. The problem is if I need to declare the following code for the
calendar script to work:
var cal6 = new calendar1(document.forms['formname'].elements['fieldname']);
cal6.year_scroll = true;
cal6.time_comp = false;

where the # 6 will change as the user adds a new field (by clicking a
button).

My problem is that the code doesn't seem to execute during run-time.
If I add the code to the include file after the field is created it
still doesn't recognise that the calendar objects exists. Can anyone
help??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top