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

var from one HTML file to another

In JavaScript, how do you pass a var from one HTML file to another
one? I "own" both of these HTML files.

Scott
Jul 23 '05 #1
3 995
Scottie wrote:
In JavaScript, how do you pass a var from one HTML file to another
one? I "own" both of these HTML files.


Cookies, parsing the query string, frames, some server side language reading
POST, GET or the cookies and writing a <script> element dynamically. There
are several options.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Jul 23 '05 #2
David,

What I did was:
var str = window.location.search;
if (str != "") {
var temp = str.split('=');
alert(temp[1]);
}
else {
alert("This is NULL");
}

and it works. Thanks.

Scott
David Dorward <do*****@yahoo.com> wrote in message news:<c8*******************@news.demon.co.uk>...
Scottie wrote:
In JavaScript, how do you pass a var from one HTML file to another
one? I "own" both of these HTML files.


Cookies, parsing the query string, frames, some server side language reading
POST, GET or the cookies and writing a <script> element dynamically. There
are several options.

Jul 23 '05 #3
Scottie wrote:
David,

What I did was:
var str = window.location.search;
if (str != "") {
var temp = str.split('=');
alert(temp[1]);
What if str.split('=') doesn't create an array, or doesn't create more then one element in the array?
What if there are multiple items being passed on the URL? You'll get both the first value and all the
remaining text from window.location.search.

}
else {
alert("This is NULL");
No, it's not null, because that's not what you're testing str against. Your condition says [if (str !=
"") {], so the else branch of that condition is that (str == ""). In fact, if str is null, it will take
the positive branch (because (null != ""), which will result in an error when you attempt to do
str.split().
}

and it works. Thanks.

Scott


Here is a much better solution:

var s = window.location.search;
// set s for testing
s = 'a=b&c=d&YourAttribute=MyValue&e=f&g=h';

// find the exact value associated with your attribute
(new RegExp('YourAttribute=([^&]+)')).test(s);
if (RegExp.$1) {
alert(RegExp.$1);
} else {
alert('There is no value for "YourAttribute"');
}

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #4

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

Similar topics

9
by: Dave Smithz | last post by:
Hi, Summary: Best way to divide out the HTML and PHP in some code I inherited. How can I keep the HTML files separate? Full Details: I've now been working two weeks on PHP / MySQL code I...
0
by: ym | last post by:
Hi, Has anybody done this before... The current html file has to 2 drop down boxes. Depending on the selection chosen, there is a predetermined html file to load. My new asp file will...
13
by: TinyTim | last post by:
I'm a newbie at ASP & HTML. It seems that when you use server side code and you're going to return a customized HTML form with several fields and labels, you have to do an extensive amount of...
7
by: Go USA! Go Israel! | last post by:
I was wondering if the following was possible: Instead of using a frameset which references other individual HTML files, have the <SPAN> tag reference another HTML file, which is placed within...
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
1
by: Tarlanim | last post by:
Hi, i'm looking for a way to pass parameter from a HTML-File to a XML-File. In HTML-File i have a reference to XML-File and i want to use the parametre from the HTML-File in XML-File (Parameter...
4
by: Neil.Smith | last post by:
I can't seem to find any references to this, but here goes: In there anyway to parse an html/aspx file within an asp.net application to gather a collection of controls in the file. For instance...
6
by: Shawn | last post by:
Hello: I have the following code in a PHP file. An HTML form passes user comment data to the PHP, which then appends the user comments to the end of the HTML file on which the form is located....
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
42
by: Santander | last post by:
how to decode HTML pages encoded like this: http://www.long2consulting.com/seeinaction2008/Simplicity_Beach_table/index.htm Is there script that will do this automatically and generate normal fully...
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
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
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,...
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...
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
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
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...

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.