I am calling a JavaScript function ChangePaymentType on the onChange event of a <select> dropdown. This function is supposed to use javascript to set a few cookies and then change the page. My current code works in IE and in Opera (both the cookie setting and the page redirection), but it doesn't work in any netscape variant (Netscape 7, Mozilla, or Firebird). The cookies are not set and the page change never happens on those browsers. Can anyone tell me why?
I was setting document.Cookie directly in the function but because it wasn't working I downloaded a SetCookie function from
http://faculty.necc.mass.edu/eschuster/cis230_f2001/s_js_bible_lst18-03.htm - but it still doesn't work in Netscape.
Response.Write "<Select class='mainForm' name='PaymentTypeID' onChange='javascript:Chang
ePaymentTy
pe(""" & thispage & """, PaymentTypeID options[PaymentTypeID.sele
ctedIndex]
.value);'>
" & CHR(10)
function SetCookie (name,value,expires,path,d
omain,secu
re) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
function ChangePaymentType(pagepref
ix, paymentidval) {
SetCookie("ShipToName", main.ShipToName.value,null
,null,null
,null)
SetCookie("ShipToAddress1"
, main.ShipToAddress1.value,
null,null,
null,null)
SetCookie("ShipToAddress2"
, main.ShipToAddress2.value,
null,null,
null,null)
SetCookie("ShipToCity", main.ShipToCity.value,null
,null,null
,null)
SetCookie("ShipToState", main.ShipToState.value,nul
l,null,nul
l,null)
SetCookie("ShipToZip", main.ShipToZip.value,null,
null,null,
null)
window.location.href = pageprefix + "&shoppingcart_action=chec
kout2&Paym
entTypeID=
" + paymentidval;
}
I also tried calling the SetCookie function without the null values at the end (as the author's instructions say they are optional) but I get the same results. If I comment out all the SetCookie calls with /* */ then the window.location does change correctly in Netscape.
I know the function IS being called in Netscape because if I put an alert() as the first line I see the alert, but then the rest of the function fails (silently, with no errors and no page redirection happens).
Part 2: Of all the different ways to change a page's location (document.location, document.location.replace(
), window.location, window.location.href, window.location.replace())
- which is the "standard" accepted way to do it, and which way is more universal? What does the W3C recommend?
Start Free Trial