/    Sign up×
Community /Pin to ProfileBookmark

How to help (function calls)

Since I am not a full time programmer, I need a little help in find a way to call a javascript from a function. Here is an example of what I am trying to do:

function update_info()
{
<script> language=”JavaScript” type=”text/JavaScript” src=”infobar1.js” </script>
}

Is this correct? Looks like it should work but does not.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@gogelpotNov 28.2006 — Try

document.write(<script> language="JavaScript" type="text/JavaScript" src="infobar1.js" </script>)
Copy linkTweet thisAlerts:
@baseiberNov 28.2006 — Normally you would put the source for your javascript in the header of your document.

[CODE]
<html>
<head>
<title>My Page</title>
<script language="JavaScript" type="text/JavaScript" src="infobar1.js">
</script>
</head>
<body>
<!-- content goes here -->
</body>
</html>
[/CODE]


Then you can call a function when you need it
[CODE]
<input type="button" name="btnButton" id="btnButton" onclick="update_info();" />
[/CODE]


There are other ways of calling a function. It depends on what you are doing.
Copy linkTweet thisAlerts:
@mrhooNov 28.2006 — [CODE]function update_info(srcpath){
var pa= document.getElementsByTagName('head')[0];
var el= document.createElement('script');
el.setAttribute('type','text/javascript');
el.setAttribute('src',srcpath);
pa.appendChild(el);
return el;
}[/CODE]


This appends a new script with src=srcpath to the document head.

The first time you need to use something from that script you will

need to set up a polling timer to check for its availability- it may take a second or more to download. I'd set an upper limit, in case of network troubles.

Alternatively, you could use AJAX...
Copy linkTweet thisAlerts:
@ashbrookauthorNov 28.2006 — Thanks all for the current replies. The reason for using a function call is that I need to update the information once a minute using the "window.settimeout" parameter. I was calling the function from the "onload" command. If there is a better way, I am open for suggestions.
Copy linkTweet thisAlerts:
@mrhooNov 28.2006 — The better way is to use a database and call the query with AJAX,

with a php (or asp) fallback
×

Success!

Help @ashbrook 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.18,
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,
)...