/    Sign up×
Community /Pin to ProfileBookmark

[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]

[CODE]
<select id=”Do” onchange=”DoWhat();”>
<option value=”DoThis”>DoThis</option>
<option value=”DoThat”>DoThat</option>
<option value=”DoTheOther”>DoTheOther</option>
</select>[/CODE]

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>
[/CODE]

Can anyone point out what if anything is wrong with this? Many thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@JonaOct 07.2010 — [font=arial]Hi,

Load the page in your browser. Type the following in your address bar:[/font]

<i>
</i>javascript:DoThis();


[font=arial]If your [/font][font=monaco]DoThis()[/font][font=arial] 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.[/font]
Copy linkTweet thisAlerts:
@RPJDauthorOct 07.2010 — 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.
×

Success!

Help @RPJD 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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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