/    Sign up×
Community /Pin to ProfileBookmark

javascript : sending and receiving parameter

Hi,

I’m new to javascript, only know the .net environment.
I would like to use javascript on my pages. I guess i wud need some help to do that.

File 1 => a.html
File 2 => b.js
File 3 => c.html

So what i want to do is pass a variable from [B]file 1[/B] to [B]file 3[/B] , but it needs to go thru [B]file 2[/B]. so [B]File 1[/B] willl send to [B]File 2[/B] then [B]file 2[/B] will send to [B]file 3[/B].

So this is what i currently have

File 1:

[CODE]getdelay(2000);[/CODE]

File 2 – (so i belive this code will save the sent value to var delayy?)

[CODE]function getdelay(ms2) {

delayy = ms2;

}[/CODE]

But then i’m not sure how to send that value from [B]File 2[/B] to [B]File 3[/B].

I will really appreciate it if you can redirect me to the right direction.

Thank You

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@nathanwallApr 30.2012 — Assuming you are talking about leaving page a.html and going to c.html (and not using iframes or something similar), then you have 3 options:

[B](1)[/B] Send the variable in a hash-style query string:

<i>
</i>location.href = 'c.html#!delayy=' + delayy;


Then you'll need to read and parse the query string in c.html.

<i>
</i>var hash = location.hash;
if(hash &amp;&amp; hash.charAt(0) == '!') {
var hashInfo = hash.split('=');
if(hashInfo[0] == '!delayy') {
delayy = hashInfo[1];
alert('delayy is ' + delayy);
}
}


Note: You could also use a "?" style query string as long as you're using an HTTP server of some kind.

[B](2)[/B] Use a cookie to transfer the variable.

Look up document.cookie for more information on this.

[B](3)[/B] Use [url=http://en.wikipedia.org/wiki/Web_Storage]web storage[/url].
Copy linkTweet thisAlerts:
@mikedonkaauthorApr 30.2012 — Thank you for the quick reply. I think the best method for me to use will be the hash-style query string. I will give that a try.

thx
Copy linkTweet thisAlerts:
@nathanwallApr 30.2012 — Part of that needs to be fixed. I didn't realize the # was included in location.hash.

<i>
</i>var hash = location.hash;
if(hash &amp;&amp; hash.substring(0, 2) == '#!') {
var hashInfo = hash.split('=');
if(hashInfo[0] == '#!delayy') {
delayy = hashInfo[1];
alert('delayy is ' + delayy);
}
}
×

Success!

Help @mikedonka spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...