Dynamically declare objects in javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Secondpost

    Dynamically declare objects in javascript

    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(docum ent.forms['formname'].elements['fieldname']);
    cal6.year_scrol l = 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

    #2
    Re: Dynamically declare objects in javascript

    How about using an array:

    var cal = new Array();

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

    jobrien55@eirco m.net (Secondpost) wrote in message news:<2500f605. 0311100548.7aa7 ab7d@posting.go ogle.com>...[color=blue]
    > 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(docum ent.forms['formname'].elements['fieldname']);
    > cal6.year_scrol l = 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??[/color]

    Comment

    • Secondpost

      #3
      Re: Dynamically declare objects in javascript

      The script I've put into the head is :

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

      function myfun(index){
      calnew[index] = new calendar1(docum ent.forms['myform'].elements['txtTaskStartDa te1']);
      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.

      indyjones48@cli ffhanger.com (Mike Jones) wrote in message news:<8c0dec93. 0311101143.3647 07c3@posting.go ogle.com>...[color=blue]
      > How about using an array:
      >
      > var cal = new Array();
      >
      > function someFunction(in dex) {
      > cal[index] = new calendar1(etc.. .)
      > cal[index].year_scroll = true
      > }
      >
      > jobrien55@eirco m.net (Secondpost) wrote in message news:<2500f605. 0311100548.7aa7 ab7d@posting.go ogle.com>...[color=green]
      > > 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(docum ent.forms['formname'].elements['fieldname']);
      > > cal6.year_scrol l = 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??[/color][/color]

      Comment

      Working...