Advertisement

12.31.2003 at 07:25AM PST, ID: 20838030
[x]
Attachment Details

Document.Cookie prevents window.location from working on Netscape, Mozilla

Asked by rlively in JavaScript

Tags: mozilla, onchange

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:ChangePaymentType(""" & thispage & """, PaymentTypeID options[PaymentTypeID.selectedIndex].value);'>" & CHR(10)

function SetCookie (name,value,expires,path,domain,secure) {
      document.cookie = name + "=" + escape (value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
}
 
function ChangePaymentType(pageprefix, 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,null,null,null,null)      
      SetCookie("ShipToZip", main.ShipToZip.value,null,null,null,null)      

      window.location.href = pageprefix + "&shoppingcart_action=checkout2&PaymentTypeID=" + 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
[+][-]12.31.2003 at 07:28AM PST, ID: 10021713

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2003 at 07:29AM PST, ID: 10021718

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2003 at 07:33AM PST, ID: 10021741

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: mozilla, onchange
Sign Up Now!
Solution Provided By: devic
Participating Experts: 3
Solution Grade: A
 
 
[+][-]12.31.2003 at 07:51AM PST, ID: 10021836

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2003 at 09:01AM PST, ID: 10022225

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.31.2003 at 10:28AM PST, ID: 10022751

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.31.2003 at 10:36AM PST, ID: 10022800

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32