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

Simple problem with function.

Hi, simple question I guess. The question is actually in the code itself as
this was the simplest way to explain.

....
var favorite = GetCookie('lang');

if (favorite != null) {
switch (favorite) {
case 'nederlands' : url = 'ned.html';
break;
case 'english' : url = 'en.html';
break;
case 'francais' : url = 'fr.html';
break;
case 'deutsch' : url = 'de.html';
break;
case 'italiano' : url = 'I dont want you to take another page, continue
loading this page because this is the italiano page';

}
window.location.href = url;
}
....

Anyone can give me the magic word I'm searching for? I thought it was "self"
but that didn't do the trick, damn :-). And when I leave it empty then it
hangs in a loop. I just want to say "when case is Italiano skip "the
window.location.href" part and continue loading this page.

Many Thanks!
--

Grtz,
Koen Colen
Jul 20 '05 #1
6 1335
> Hi, simple question I guess. The question is actually in the code itself as
this was the simplest way to explain.

var favorite = GetCookie('lang');

if (favorite != null) {
switch (favorite) {
case 'nederlands' : url = 'ned.html';
break;
case 'english' : url = 'en.html';
break;
case 'francais' : url = 'fr.html';
break;
case 'deutsch' : url = 'de.html';
break;
case 'italiano' : url = 'I dont want you to take another page, continue
loading this page because this is the italiano page';

}
window.location.href = url;
}
...

Anyone can give me the magic word I'm searching for? I thought it was "self"
but that didn't do the trick, damn :-). And when I leave it empty then it
hangs in a loop. I just want to say "when case is Italiano skip "the
window.location.href" part and continue loading this page.


First, the title of the message is wrong. This isn't a function. A function is a
very specific and useful thing. Call things by their correct names.

Second, you are using a switch statement to do something better done with an
object.

var pages = {nederlands: 'ned.html', english: 'en.html', francais:
'fr.html', deutsch: 'de.html'};

function lang_page(lang) {
var u = pages[lang];
if (typeof u == 'string') {
window.location.href = u;
}
}

http://www.crockford.com/#javascript

Jul 20 '05 #2
On Mon, 19 Jan 2004 21:26:47 GMT, koen colen <ko********@pandora.be> wrote:
Anyone can give me the magic word I'm searching for? I thought it was
"self" but that didn't do the trick, damn :-). And when I leave it
empty then it hangs in a loop. I just want to say "when case is
Italiano skip "the window.location.href" part and continue loading
this page.


Simply modify it to:

function changePage() {
var favorite = GetCookie('lang');
var url = null;

if (favorite != null) {
switch (favorite) {
case 'nederlands':
url = 'ned.html';
break;
case 'english':
url = 'en.html';
break;
case 'francais':
url = 'fr.html';
break;
case 'deutsch':
url = 'de.html';
break;
case 'italiano':
// no action
break;
}
}
if (url) window.location.href = url;
}

If you're trying to reload the page, you could replace "// no action" with
"window.location.reload();".

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #3
That was exactly what I was looking for Mike. Many thanks! Thanks for the
reply Douglas!

And I'm meaning it :-)
Koen
"Michael Winter" <M.******@blueyonder.co.invalid> schreef in bericht
news:op**************@news-text.blueyonder.co.uk...
On Mon, 19 Jan 2004 21:26:47 GMT, koen colen <ko********@pandora.be> wrote:
Anyone can give me the magic word I'm searching for? I thought it was
"self" but that didn't do the trick, damn :-). And when I leave it
empty then it hangs in a loop. I just want to say "when case is
Italiano skip "the window.location.href" part and continue loading
this page.


Simply modify it to:

function changePage() {
var favorite = GetCookie('lang');
var url = null;

if (favorite != null) {
switch (favorite) {
case 'nederlands':
url = 'ned.html';
break;
case 'english':
url = 'en.html';
break;
case 'francais':
url = 'fr.html';
break;
case 'deutsch':
url = 'de.html';
break;
case 'italiano':
// no action
break;
}
}
if (url) window.location.href = url;
}

If you're trying to reload the page, you could replace "// no action" with
"window.location.reload();".

Hope that helps,
Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)

Jul 20 '05 #4
koen colen wrote on 19 jan 2004 in comp.lang.javascript:
var favorite = GetCookie('lang');

if (favorite != null) {
switch (favorite) {
case 'nederlands' : url = 'ned.html';
break;
case 'english' : url = 'en.html';
break;
case 'francais' : url = 'fr.html';
break;
case 'deutsch' : url = 'de.html';
break;
case 'italiano' : url = 'I dont want you to take another page, continue
loading this page because this is the italiano page';

}
window.location.href = url;
}
...


Ik zou het zo doen:

var favorite = GetCookie('lang'); // in fact unknown function?
if (favorite == 'nederlands') location.href='ned.html';
if (favorite == 'english') location.href='en.html';
if (favorite == 'francais') location.href='fr.html';
if (favorite == 'deutsch') location.href='de.html';
// 'italiano'
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #5
Michael Winter wrote on 19 jan 2004 in comp.lang.javascript:
On Mon, 19 Jan 2004 21:26:47 GMT, koen colen <ko********@pandora.be>
wrote:
Anyone can give me the magic word I'm searching for? I thought it was
"self" but that didn't do the trick, damn :-). And when I leave it
empty then it hangs in a loop. I just want to say "when case is
Italiano skip "the window.location.href" part and continue loading
this page.


Simply modify it to:

function changePage() {
var favorite = GetCookie('lang');
var url = null;

if (favorite != null) {
switch (favorite) {
case 'nederlands':
url = 'ned.html';
break;
case 'english':
url = 'en.html';
break;
case 'francais':
url = 'fr.html';
break;
case 'deutsch':
url = 'de.html';
break;
case 'italiano':
// no action
break;
}
}
if (url) window.location.href = url;
}

If you're trying to reload the page, you could replace "// no action"
with "window.location.reload();".


Then it would reload forever !
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #6
On 20 Jan 2004 00:28:53 GMT, Evertjan. <ex**************@interxnl.net>
wrote:
If you're trying to reload the page, you could replace "// no action"
with "window.location.reload();".


Then it would reload forever !


That's an incredibly good point.

I've e-mailed the OP to apprise him of that absurdly stupid error. Thank
you so much, Evertjan, for saying that.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Jul 20 '05 #7

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

Similar topics

11
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
24
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
14
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
26
by: optimistx | last post by:
A variable in global scope var a1 = 'contents of global variable a1'; can be references (with some limitations) as window; // or window.a1; // or even window;
17
by: Chris M. Thomasson | last post by:
I use the following technique in all of my C++ projects; here is the example code with error checking omitted for brevity: _________________________________________________________________ /*...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.