Dynamically declare objects in javascript

Discussion in 'Javascript' started by Secondpost, Nov 10, 2003.

  1. Secondpost

    Secondpost Guest

    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??
    Secondpost, Nov 10, 2003
    #1
    1. Advertising

  2. Secondpost

    Mike Jones Guest

    How about using an array:

    var cal = new Array();

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

    (Secondpost) wrote in message news:<>...
    > 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??
    Mike Jones, Nov 10, 2003
    #2
    1. Advertising

  3. Secondpost

    Secondpost Guest

    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.

    (Mike Jones) wrote in message news:<>...
    > How about using an array:
    >
    > var cal = new Array();
    >
    > function someFunction(index) {
    > cal[index] = new calendar1(etc...)
    > cal[index].year_scroll = true
    > }
    >
    > (Secondpost) wrote in message news:<>...
    > > 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??
    Secondpost, Nov 11, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SXNoYWFu?=

    variable declare dynamically

    =?Utf-8?B?SXNoYWFu?=, Mar 19, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    389
  2. =?Utf-8?B?ZGF2aWQ=?=

    How dynamically declare Image controls in a web form?

    =?Utf-8?B?ZGF2aWQ=?=, Jan 9, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,770
    =?Utf-8?B?ZGF2aWQ=?=
    Jan 9, 2006
  3. Philipp
    Replies:
    5
    Views:
    6,463
    Ron Natalie
    Oct 16, 2003
  4. macm
    Replies:
    1
    Views:
    206
    Ian Kelly
    Nov 11, 2010
  5. how can i declare a varible dynamically

    , Sep 12, 2008, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    93
Loading...

Share This Page