473,390 Members | 1,306 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,390 software developers and data experts.

Passing parameters to external JS file?

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

Kinne
Jul 23 '05 #1
5 37788
"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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.