473,796 Members | 2,712 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 1647
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
2427
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
4522
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
4071
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
2384
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
1789
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
2351
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
4690
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
1935
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
1822
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
9524
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
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
9047
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
7546
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
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5440
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
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

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.