473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Basic Question on calling javascripts

JCO
I have several JavaScripts in a web page. Each script is in an individual
file with extension .js.
I want to know if it is possible to put all functions in one single page.
If so, how do I call the specific script that I want to run.

This is how I call an individual script:
<SCRIPT LANGUAGE="JavaScript" src="valForm.js"></SCRIPT>

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPassword.txtInput.value == "password" )
document.location.href="Private.htm";
else
document.location.href="NoAccessPage.htm";
}
If a single script contains 5-10 functions, how do you call the specific
function you want?

Thanks in advance.

Jul 20 '05 #1
7 1620
I have read the following message from " JCO" <J.********@verizon.net>
and have decided to lend my vast knowledge.

The writer said:
I have several JavaScripts in a web page. Each script is in an individual
file with extension .js.
I want to know if it is possible to put all functions in one single page.
If so, how do I call the specific script that I want to run.

This is how I call an individual script:
<SCRIPT LANGUAGE="JavaScript" src="valForm.js"></SCRIPT>

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPassword.txtInput.value == "password" )
document.location.href="Private.htm";
else
document.location.href="NoAccessPage.htm";
}
If a single script contains 5-10 functions, how do you call the specific
function you want?

Thanks in advance.

and my reply is:
The name of a js file has nothing to do with the name of the function
inside. In fact a script may not even contain a function. You can one
or multiple js files depending on how you use them. The browser loads
them all into the page and does't care where they came from. Just name
them anything you want.
function xxx() {
....
};
function yyy() {
....
};

function zzz() {
....
};
Put the above in 1, 2, or 3 js files. It doesn't matter.
To use a function just refer to it's name
xxx() or yyy() or zzz()

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #2
" JCO" <J.********@verizon.net> wrote in message
news:m2*****************@nwrddc01.gnilink.net...
I have several JavaScripts in a web page. Each script is in an individual
file with extension .js.
I want to know if it is possible to put all functions in one single page.
If so, how do I call the specific script that I want to run.

This is how I call an individual script:
<SCRIPT LANGUAGE="JavaScript" src="valForm.js"></SCRIPT>

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPassword.txtInput.value == "password" )
document.location.href="Private.htm";
else
document.location.href="NoAccessPage.htm";
}
If a single script contains 5-10 functions, how do you call the specific
function you want?

Thanks in advance.


Just merge them into a single include file and run it.

Nothing else has to change unless, perhaps, if there are duplicate function
names or global variables declared.
Functions are called in numerous ways:

<body onload="func1()">

<form onsubmit="return func2()">

<img src="button.gif" onclick="func3()">

and, of course, from within other functions.
Does this help?
Jul 20 '05 #3
Lee
JCO said:

I have several JavaScripts in a web page. Each script is in an individual
file with extension .js.
I want to know if it is possible to put all functions in one single page.
If so, how do I call the specific script that I want to run.
Your terminology is likely to cause confusion at some point.
A program written in C++ is not "a C++".
A script written in JavaScript is not "a JavaScript".

This is how I call an individual script:
<SCRIPT LANGUAGE="JavaScript" src="valForm.js"></SCRIPT>
That's not really "calling" anything. That's telling the browser
where to load a block of JavaScript from. The browser loads the
code block into the current page, making the functions available
and executing any in-line code they may contain.

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPassword.txtInput.value == "password" )
document.location.href="Private.htm";
else
document.location.href="NoAccessPage.htm";
}
If a single script contains 5-10 functions, how do you call the specific
function you want?


The only way to call a function is to invoke it by name,
as in "valform()". It doesn't matter where the browser
loads it from. It's either loaded into the current page,
or it isn't.

Jul 20 '05 #4
JCO
Thanks all three for your reply. I guess I was getting confused because in
my example, the name of the js script is also the name of the file source.
Now I realized that the source file is loaded one time which makes all of
the functions available to my website.

Very cool! Thanks again
"Lee" <RE**************@cox.net> wrote in message
news:c0********@drn.newsguy.com...
JCO said:

I have several JavaScripts in a web page. Each script is in an individualfile with extension .js.
I want to know if it is possible to put all functions in one single page.
If so, how do I call the specific script that I want to run.


Your terminology is likely to cause confusion at some point.
A program written in C++ is not "a C++".
A script written in JavaScript is not "a JavaScript".

This is how I call an individual script:
<SCRIPT LANGUAGE="JavaScript" src="valForm.js"></SCRIPT>


That's not really "calling" anything. That's telling the browser
where to load a block of JavaScript from. The browser loads the
code block into the current page, making the functions available
and executing any in-line code they may contain.

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPassword.txtInput.value == "password" )
document.location.href="Private.htm";
else
document.location.href="NoAccessPage.htm";
}
If a single script contains 5-10 functions, how do you call the specific
function you want?


The only way to call a function is to invoke it by name,
as in "valform()". It doesn't matter where the browser
loads it from. It's either loaded into the current page,
or it isn't.

Jul 20 '05 #5
I recently learned that language="javascript" is deprecated in favor of
type="text/javascript"

Just a remark.
--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Jul 20 '05 #6
JCO
Yes I have noticed that too. I made the changes.
However, can you tell me the difference in the code below:

<FORM NAME="frmPassword" onSubmit="return valForm()">
<FORM NAME="frmPassword" onEnter="return valForm()">

"Bas Cost Budde" <ba*@heuveltop.org> wrote in message
news:c0**********@news2.solcon.nl...
I recently learned that language="javascript" is deprecated in favor of
type="text/javascript"

Just a remark.
--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Jul 20 '05 #7
JCO wrote:
However, can you tell me the difference in the code below:

<FORM NAME="frmPassword" onSubmit="return valForm()">
<FORM NAME="frmPassword" onEnter="return valForm()">


Er, the first line uses the Submit event? That shall not be your question.

(reads the HTML 4.01 spec) I can't find an onEnter property. What is
that supposed to mean?

--
Bas Cost Budde
http://www.heuveltop.org/BasCB
but the domain is nl

Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kerberos | last post by:
When I deliver a page as text/html, the javascripts work, but if delivered as application/xhtml+xml, the javascripts don't work: function OpenBrWindow(theURL,winName,features, myWidth, myHeight,...
7
by: Julia Briggs | last post by:
Hello World - I admit I'm new to javascript but I've tried for days to find a solution to my problem. Basically I have 3 unique javascript files that do different screen display events that I...
4
by: Smoke | last post by:
We had a javascript calling a Cold Fusion page (.cfm) and it was working for 2 years. Suddenly yesterday or today its decided it doesn't want to work anymore. I'm picking up somebody elses code I...
2
by: sdvoranchik | last post by:
We have an application that contains links that run javascripts to create pages in a separate frame. When these links open an external site, it causes the javascripts to no longer function. When...
2
by: LC's No-Spam Newsreading account | last post by:
I asked a couple of days ago about the following arrangement (simplified). I made some progress using netscape.security.PrivilegeManager.enablePrivilege but still have to ask some further help. ...
4
by: David Virgil Hobbs | last post by:
My web host inserts banner ads into my html pages. The javascript in these banner ads interferes with the onload triggered javascript functions in my pages. Whether I trigger my javascript...
8
by: Jakej | last post by:
I've been using a javascript in an html file for a banner slider, and it works as desired. But I'd like to use it on more than one page and it would be great if I could transfer the code to a .js...
12
by: Mark Fox | last post by:
Hello, I am attempting to do something very simple. I have a page MainPage.aspx and a popup window Popup.aspx. When users click on the linkbutton in the popup window I am looking to do some...
4
by: januarynow | last post by:
Generally, my site contains javascripts (a couple of freebie counters plus some CPM (pay-per-impression) and CPC (pay-per-click) ads), from four different firms, but they are all suffering from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.