PDA

View Full Version : help please


habib
09-23-2002, 03:54 PM
I keep getting a syntax error and I can't work out what is wrong with this piece of code:

function doLink() {
var name='home_location';
var cookieVal=getCookie(name);
//switch (cookieVal) {
if (getCookie('home_location') == 'UK') {
document.location='contact.htm'; }
else
if (getCookie('home_location') == 'SA') {
document.location='location-africa-southafrica.htm';
}
}

Thanx in advance for all your help

beetle
09-23-2002, 04:04 PM
location is a sub-object to window, not document AND you need to modify the href property.

Although it's perfectly valid to include "window", in most cases that is implied so it is unecessary.function doLink() {
var name='home_location';
var cookieVal=getCookie(name);
//switch (cookieVal) {
if (getCookie('home_location') == 'UK') {
location.href='contact.htm'; }
else
if (getCookie('home_location') == 'SA') {
location.href='location-africa-southafrica.htm';
}
}

beetle
09-23-2002, 04:07 PM
Oh, and to properly code that function to use the switch/case statement would look like thisfunction doLink() {
var cookieVal=getCookie('home_location');
switch (cookieVal) {
case 'UK' : location.href='contact.htm';break;
case 'SA' : location.href='location-africa-southafrica.htm';break;
default : alert('Cookie value not found!');
}
}

habib
09-23-2002, 05:16 PM
Wow! Waddaya know, it works!

Thankyou very much Beetle for taking timeout in helping solve this problem.


:thumbsup: