473,671 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript" src="valForm.js "></SCRIPT>

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPas sword.txtInput. value == "password" )
document.locati on.href="Privat e.htm";
else
document.locati on.href="NoAcce ssPage.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 1641
I have read the following message from " JCO" <J.********@ver izon.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="JavaS cript" src="valForm.js "></SCRIPT>

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPas sword.txtInput. value == "password" )
document.locati on.href="Privat e.htm";
else
document.locati on.href="NoAcce ssPage.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.********@ver izon.net> wrote in message
news:m2******** *********@nwrdd c01.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="JavaS cript" src="valForm.js "></SCRIPT>

Where valForm is a script that looks like this:
function valForm()
{
if( document.frmPas sword.txtInput. value == "password" )
document.locati on.href="Privat e.htm";
else
document.locati on.href="NoAcce ssPage.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="retur n 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="JavaS cript" 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.frmPas sword.txtInput. value == "password" )
document.locati on.href="Privat e.htm";
else
document.locati on.href="NoAcce ssPage.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.co m...
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="JavaS cript" 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.frmPas sword.txtInput. value == "password" )
document.locati on.href="Privat e.htm";
else
document.locati on.href="NoAcce ssPage.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="javas cript" 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="frmPasswo rd" onSubmit="retur n valForm()">
<FORM NAME="frmPasswo rd" onEnter="return valForm()">

"Bas Cost Budde" <ba*@heuveltop. org> wrote in message
news:c0******** **@news2.solcon .nl...
I recently learned that language="javas cript" 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="frmPasswo rd" onSubmit="retur n valForm()">
<FORM NAME="frmPasswo rd" 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
2411
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, isCenter) { //v3.0 if(window.screen)if(isCenter)if(isCenter=="true"){ var myLeft = (screen.width-myWidth)/2; var myTop = (screen.height-myHeight)/2; features+=(features!='')?',':''; features+=',left='+myLeft+',top='+myTop;
7
4514
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 want to dynamically call, where the current page would then refresh after a user clicks on any one of three associated button links. Could someone please assist me and craft a simple script that would accomplish this feat of impossibility? ...
4
4060
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 don't know all of the rules here. All of the examples I've found really want .JS files if called with a script tag, example below. <script src="http://www.website.com/javascripts/xxx.js"> </script>
2
2379
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 we modified the links that invoke the javascripts from: <a href=javascript: top.doSomething> text </a> To: <span onclick=javascript:top.doSomething> text </span> The javascripts worked properly. Any ideas on why this now works or other...
2
1779
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. 1) a frameset contains - a number of javascript functions in the head (they do something like top.frames.document.myform.elements.value = v - two frames UP and DOWN
4
2345
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 functions through onload=function() in the body tag or through window.onload=function name in a script, the host's advertising javascripts disrupt my javascripts that are supposed to run onload so that they do not run. I am not able to control the...
8
4666
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 file and call it with the <script src="filename.js"></script> tags as I do for many other .js files. But, when I try to do that way, it doesn't work right. It will display the banner text, but only on the 0,0 page coordinate and doesn't slide....
12
1914
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 server side processing in Popup.aspx, then have the popup window close, and have the MainPage.aspx do a postback to the server. But I am having trouble determining what client side javascript Popup.aspx should render after it does its server side
4
1818
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 same problem: every day, they have a 90%+ failure rate, in detecting traffic. My server log keeps reporting that numerous people visit the site, but those javascript companies keep saying otherwise. I have reason to believe that the server log is...
0
8483
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8825
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8605
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8676
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7445
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6237
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.