/    Sign up×
Community /Pin to ProfileBookmark

Delayed array population possible?

I would like to know if there is anyway to delay the population of an array using javascript. The sequence of what I want to do is:

  • 1. Start HTML site

  • 2. Define: var AnyArray = new Array();

  • 3. Be able to click on button that fills the ‘AnyArray’ with the contents of an external.js file that contains only data (no functions)
  • In otherwords, the array would normally be initialize as blank,
    then I could
    a. fill as needed with operator entered information and jump to step c. below

    b. or click on a button to fill the array with previously saved information that I can then modify with other operator information.

    c. and finally, I could then copy and paste the contents of the AnyArray that I write to a <textarea> element.

    My problem is that I don’t know how to define the array in the initial HTML file so that when I load the external.js file (that overwrites the AnyArray information) I don’t get an error with duplicate definitions. Any ideas? ?

    to post a comment
    JavaScript

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @EricWAug 21.2006 — Look into Ajax, if the external.js is dynamic or there are too many permutations to preload. If it is small amount of static data just load a bunch of functions to load your array and manipulate the textarea.
    Copy linkTweet thisAlerts:
    @JMRKERauthorAug 22.2006 — Here is an example: ?

  • 1. The 'External.js' file load correctly when script is started.

  • 2. The Show button verifies the file loaded

  • 3. The Clear AnyArray button clears the loaded information

  • 4. The Show button verifies the array is cleared

    BUT

  • 5. How do I re-load the 'External.js' file again (with out browser refresh) ???


  • Contents of 'External.html' demo HTML
    [code=php]
    <html>
    <head>
    <title>Load External.JS File</title>
    <script type="text/javascript" src='External.js'></script>
    <script type="text/javascript">
    <!--
    function LoadJSfile() {
    // WHAT DO I DO HERE TO GET 'External.js' CONTENTS AGAIN ?????
    // AFTER CLEARING ARRAY TO NULL ?????

    }
    function ShowJSfile() {
    document.getElementById('TA').value = "";
    var str = "";
    for (i=0; i<AnyArray.length; i++) {
    str += AnyArray[i]+"n";
    }
    document.getElementById('TA').value = str;
    }
    //-->
    </script>
    </head>
    <body>
    <textarea id="TA" rows="8" cols="40" wrap="off"></textarea>
    <br />
    <button onClick="ShowJSfile()">Show 'External.js' file</button>
    <button onClick="document.getElementById('TA').value=''";>Clear Text</button>
    <br />
    <button onClick="AnyArray=[]";>Clear AnyArray</button>
    <button onClick="LoadJSfile()">Re-Load 'External.js' file</button>
    </body>
    </html>
    [/code]

    Contents of 'External.js'
    [code=php]
    // External.js
    var AnyArray = new Array();

    AnyArray[0] = 'First line of external.js file';
    AnyArray[1] = 'More information';
    AnyArray[2] = 'Last line of external.js file';
    [/code]


    Any ideas are appreciated as to how to re-load the external information.
    ×

    Success!

    Help @JMRKER spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 4.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,

    tipper: @Samric24,
    tipped: article
    amount: 1000 SATS,
    )...