Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JavaScript elements not working on a MAC 1

Status
Not open for further replies.

bhuninghake

Programmer
Mar 24, 2004
90
US
I'm fairly new to programming and not sure if I'm asking the question correctly, supplying enough information to be understood, but here goes. I have an online store where ASP, JavaScript, Cookies and Session variables are used throughtout where info is stored in cookies and session variables. Everything seems to work correctly with different browsers on a PC but the MAC keeps dropping information passed via JavaScript. Everything seems to work correctly on the MAC until checkout time and then I can see an error stating that the elements are not an object, but yet I can make an alert window and the MAC will display the alert windows with the correct information. Is there some special code I need to add to my asp pages when dealing with the MAC?

The JavaScript works with all browsers on the PC. On the MAC I've tried IE and Netscape with no success.
The code is part of the checkout process. Here is the code. Notice the "alert tags" that I used in my tests where the MAC does show the alerts with the correct elements.

<script language="JavaScript">
function checkout()
{

//alert("here");

//var oChkout = document.frmCheckout;
var oChkout = document.getElementById("frmCheckout");
var oCart = document.getElementById("frmCart");

//alert("temp: " + oCart.id + ", " + oChkout.id);

//loop through the cart and update the checkout form with the latest values
// in case they have changed
var oItem
//for (var i = 0; i < document.frmCart.length; i++)
//BILL: LOOK HERE!!!
//for (var i = 0; i < oCart.length; i++)
for (var i = 0; i < oCart.elements.length; i++)
{
//<%
'Note: may need to do elements.length above. May be an issue with
' the .elements[name].value = value line...
%>

oItem = oCart.elements;
//alert( "Debug: " + oChkout.elements.length );
if( oItem != null )
{
//alert(oItem.name + ": " + oChkout.elements[oItem.name].value + " --> " + oItem.value);
oChkout.elements[oItem.name].value = oItem.value;
}
}

//for (var i = 0; i < oChkout.length; i++)
//{
// alert(oChkout.elements.name + ":" + oChkout.elements.value)
//}

oChkout.submit();

}
</script>
 
Which version of Netscape are you using? Netscape 4.x doesn't support the "getElementById" method.

You might like to try:
Code:
<script language="JavaScript">
function checkout() {

	var oChkout = document.frmCheckout;
	var oCart = document.frmCart;

	// loop through the cart and update the checkout form with the latest values
	// in case they have changed
	var oItem;
	for (var i = 0; i < oCart.elements.length; i++) {
		oItem = oCart.elements[i];
		// alert( "Debug: " + oChkout.elements.length);
		if(oItem.name) {
			// alert(oItem.name + ": " + oChkout.elements[oItem.name].value + " --> " + oItem.value);
			oChkout.elements[oItem.name].value = oItem.value;
		}
	}

	for (var i=0; i < oChkout.length; i++) {
		alert(oChkout.elements[i].name + ":" + oChkout.elements[i].value)
	}

	//oChkout.submit();
	return false;
}
</script>

<form name="frmCheckout">
<input type="text" value="" name="box11" id="box11">
<input type="text" value="" name="box12" id="box12">
<input type="text" value="" name="box13" id="box13">
</form>

<form name="frmCart" onsubmit="return checkout()">
<input type="text" value="whatever1" name="box11" id="box11">
<input type="text" value="whatever2" name="box12" id="box12">
<input type="text" value="whatever3" name="box13" id="box13">
<input type="submit">
</form>

Not sure if this was what you were after.

Pete.


Web Developer & Aptrix / IBM Lotus Workplace Web Content Management (LWWCM) Specialist
w: e: Pete.Raleigh(at)lclimited.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top