www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] external functions not executing

  1. #1
    Join Date
    Mar 2007
    Posts
    31

    resolved [RESOLVED] external functions not executing

    I have a select options list where a different function is called depending on the option chosen. I'm using an internal function to check the value of the option selected, then calling an external function based on the option chosen. My problem is that I cannot get the external function to execute. I have three if statements checking three values. After each if statement I have a function call like this:
    Code:
    function DoWhat()
    {
    var what = document.getElementById('Do');
    var value = what[what.selectedIndex].value;
    if(value == 'DoThis')
    { 
    DoThis();
    }
    if(value == 'DoThat')
    { 
    DoThat();
    }
    if(value == 'DoTheOther')
    { 
    DoTheOther();
    }
    }
    Code:
    <select id="Do" onchange="DoWhat();">
    <option value="DoThis">DoThis</option>
    <option value="DoThat">DoThat</option>
    <option value="DoTheOther">DoTheOther</option>
    </select>
    If I use an alert instead of DoThis(), DoThat() or DoTheOther the alert executes. The functions are in externally linked .js files, but won't execute.
    Code:
    <script type="text/javascript" src="./JScript/DoThis.js"/></script>
    <script type="text/javascript" src="./JScript/DoThat.js"/></script>
    <script type="text/javascript" src="./JScript/DoTheOther.js"/></script>
    Can anyone point out what if anything is wrong with this? Many thanks.

  2. #2
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Hi,

    Load the page in your browser. Type the following in your address bar:


    Code:
    javascript:DoThis();
    If your DoThis() method does not execute, then you can bet the external JavaScript file has not loaded as expected. Check the file path, paying attention to case. If you're certain it should be loading, check your browser's security settings or try another browser.

    Hope this helps.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  3. #3
    Join Date
    Mar 2007
    Posts
    31
    I deleted all the code in the .js file except for the alert and it executed. I then added small bits of code back in and it still executed. Until I added an array at the end when it failed to execute. Found a syntax error in the array, a [ that should have been a ] When your half asleep you don't notice these little keystroke errors.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles