473,507 Members | 3,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameters to external JS file?

Is it possible to pass a parameter to an external ".js" file?

Kinne
Jul 23 '05 #1
5 37800
"kinne" <ki***@advalvas.be> wrote in message
news:41***********************@news.skynet.be...
Is it possible to pass a parameter to an external ".js" file?

Kinne


Not sure exactly what you mean or want.

However, you can define a variable outside of the external ".js" file and
use it within it.

<html>
<head>
<title>test2.htm</title>
<script type="text/javascript">
var parm = "HelloWorld";
</script>
<script type="text/javascript" src="external.js">
</script>
</head>
<body>
</body>
</html>

// external.js
document.write(parm);

Alternatively, you could pass a parameter via the QueryString portion of the
URL:

http://{domain}/{folder}/test2.htm?HelloWorld

<html>
<head>
<title>test1.htm</title>
<script type="text/javascript" src="external.js">
</script>
</head>
<body>
</body>
</html>

// external.js
var parm = location.search;
parm = parm.substr(1);
document.write(parm);
Jul 23 '05 #2
"kinne" <ki***@advalvas.be> wrote in message
news:41***********************@news.skynet.be...
Is it possible to pass a parameter to an external ".js" file?

Kinne


Not sure exactly what you mean or want.

However, you can define a variable outside of the external ".js" file and
use it within it.

<html>
<head>
<title>test2.htm</title>
<script type="text/javascript">
var parm = "HelloWorld";
</script>
<script type="text/javascript" src="external.js">
</script>
</head>
<body>
</body>
</html>

// external.js
document.write(parm);

Alternatively, you could pass a parameter via the QueryString portion of the
URL:

http://{domain}/{folder}/test2.htm?HelloWorld

<html>
<head>
<title>test1.htm</title>
<script type="text/javascript" src="external.js">
</script>
</head>
<body>
</body>
</html>

// external.js
var parm = location.search;
parm = parm.substr(1);
document.write(parm);
Jul 23 '05 #3
Thanks for replying!
My question was indeed very short, but the second part of you answer was the
kind of thing that I expected.
I need to call an external ".js" file and pass a parameter to it. This
parameter would be used in the file as a variable to perform some tests.
What I don't know is i) how to pass the variable to the code in the external
".js" file and ii) how to collect the passed variable to work with it within
the file.
The QueryString looks like to way to do this. Now that I have a starting
point, I'll try to find my way and more info about this. Thanks for giving
me the first clue.

Kinne
[...]
Alternatively, you could pass a parameter via the QueryString portion of the URL:

http://{domain}/{folder}/test2.htm?HelloWorld

<html>
<head>
<title>test1.htm</title>
<script type="text/javascript" src="external.js">
</script>
</head>
<body>
</body>
</html>

// external.js
var parm = location.search;
parm = parm.substr(1);
document.write(parm);

Jul 23 '05 #4
On Sun, 28 Nov 2004 21:41:39 +0100, kinne <ki***@advalvas.be> wrote:

[snip]
I need to call an external ".js" file and pass a parameter to it.


You cannot "call" a file; it's just plain text.

A SCRIPT element with a src attribute is effectively the same as a SCRIPT
element with the file contents included directly in it. Any script added
to a document shares the same global namespace, so the code in the second
SCRIPT element below can access the variables defined and initialised in
the first, irrespective of whether the code is stored in an external file
or included directly in the document.

<script type="text/javascript">
var someGlobal = 'A variable';
</script>

<script type="text/javascript">
alert(someGlobal); // 'A variable'
</script>

In summary, you don't need to "pass" anything.

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
[snip]
You cannot "call" a file; it's just plain text. [snip] In summary, you don't need to "pass" anything.

[snip]

OK Michael, I got it now ! Thanks for this clear answer.

Kinne
Jul 23 '05 #6

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

Similar topics

2
17341
by: zlatko | last post by:
There is a form in an Access Project (.adp, Access front end with SQL Server) for entering data into a table for temporary storing. Then, by clicking a botton, several action stored procedures...
7
49553
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. ...
2
46387
by: Akira | last post by:
Hello. I'm having problem with passing parameters from .aspx file to user control. Could anyone tell me how to pass parameters from .aspx file to user control(.ascx) and how to recieve parameters...
0
1541
by: Paul Allan | last post by:
I am new to ASP.net (intermediate ASP developer). I am developing a ASP.net web application and I am having some difficulty calling and passing parameters to a function that is declared in my...
4
2977
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
4
7150
by: David Freeman | last post by:
Hi There! I'm just wondering if there's a way to pass parameters (as if you were passing parameters to a ASCX web control) when calling an ASPX page? e.g. MyDetailsPage.UserName = "david" ...
1
1445
by: Jim Phelan | last post by:
I need to write a program, exe, that's called from a third party application. This third party application allows me to configure the name of the application to be called. When it executes it...
1
1890
by: john | last post by:
I'm trying to develop fast, simple, html-based front ends for some Windows application programs. My idea: 1. Use html forms to let users supply run parameters (title, run options, etc.) 2. ...
2
2011
by: Nab | last post by:
I have just tried to pass parameters to a procedure in VB 2005 and realised that you only need to pass the input parameter. The output parameter's value will be returned without the need to pass it...
0
7221
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
7109
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
7372
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...
0
7481
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
5619
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,...
1
5039
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...
0
4702
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...
0
3190
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...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.