0 Replies - 569 Views - Last Post: 10 February 2009 - 05:30 PM

#1 neoseeker191  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 18-May 08

Order Form Wont Update

Posted 10 February 2009 - 05:30 PM

I took over this website a little while back. The order form will only update the first three products, and that's only if I comment out the getTaxRate function. It doesn't update the Final Total either. I've made some attempt at getting it to work but ended up pulling my hair out. I'm not too familiar with javascript, but it seems like the code was written poorly. I would appreciate any help.

Here is the form: Link

Here is the java script:
// @@@@@ SALES ORDER SCRIPTS Start @@@@@
/*
		Return Codes
		-------------------------
		0  - Success
		1  - Error: Check sum failed
		10 - Error: Too Few digits
		11 - Error: Invalid Prefix
		12 - Error: Incorrect Number of digits
		13 - Error: Unsupported card type
	  */
	  function validateCCard( nCardNum, strCardType)
	  {
		// returns 0 if valid, positive number if invalid.
		nTotal = 1*0;
		nOff = 1*0;

		nNumber = "";

		// Remove any non-numeric values from this number.
		for( i = 0; i < nCardNum.length; i++ )
			  if ( nCardNum.charAt(i) >= "0" && nCardNum.charAt(i) <= "9" )
			nNumber = nNumber + nCardNum.charAt(i);

		nFirstNum = "" + nNumber.charAt(0);
		nSecondNum = "" + nNumber.charAt(1);
		nThirdNum = "" + nNumber.charAt(2);
		nFirstTwoDigits = nFirstNum + nSecondNum;
		nFirstFourDigits = nFirstTwoDigits + nThirdNum + nNumber.charAt(3);

		if ( strCardType == "MasterCard" )
		{
		  if ( nFirstNum != "5" || nSecondNum < "1" || nSecondNum > "5" )
			return 11;	  // invalid prefix

		  if(nNumber.length != 16)
			return 12;	  // Incorrect number of digits
		}
		else if(strCardType == "Visa")
		{
		  if(nFirstNum != "4")
			return 11;	  // invalid prefix

		  if(nNumber.length != 13 && nNumber.length != 16)
			return 12;	  // Incorrect number of digits
		}
		else if(strCardType == "American Express")
		{
		  if(nFirstNum != "3" || (nSecondNum != "4" && nSecondNum != "7"))
			return 11;	  // invalid Prefix

		  if(nNumber.length != 15)
			return 12;	  // Incorrect number of digits
		}
		else if(strCardType == "Discover")
		{
		  if( nFirstFourDigits != "6011" )
			return 11;	  // invalid prefix.

		  if( nNumber.length != 16 )
			return 12;	  // Incorrect number of digits
		}
		else if(strCardType == "Diner''s Club")
		{
		  if ( nFirstTwoDigits != "36" && nFirstTwoDigits != "38" &&
			  (nFirstTwoDigits != "30" || (nThirdNum < "0" || nThirdNum > "5")))
		  {
			return 11;	  // invalid prefix.
		  }
		  if ( nNumber.length != 14 )
			return 12;	  // Incorrect number of digits
		}
		else
		  return 13;  // Card type not supported

		// No card is less than 13 characters
		if ( nNumber.length < 13 )
		  return 10;

		// now check the credit card suffix and length vs. the type

		// do the checksum
		for ( loc = nNumber.length - 2; loc >= 0; loc -= 2 )
		{
		  nTotal += 1 * nNumber.charAt(loc +1);
		  nOff = nNumber.charAt(loc) * 2;
			if ( nOff > 9 )
			  nTotal += 1;
			nTotal += (nOff % 10);
		}

		if( nNumber.length % 2 > 0 )
		  nTotal += 1 * nNumber.charAt(0);

		if ( ( nTotal % 10 ) != 0 )
		  return 1; // Checksum failure

		return 0; // Okey Dokey!
	 }
	  function formatCurrency(nAmount)
	  {
		 //-- Returns passed number as string in $xxx,xxx.xx format.
		 nAmount=eval(nAmount)
		 workNum=Math.abs((Math.round(nAmount*100)/100));workStr=""+workNum
		 if (workStr.indexOf(".")==-1){workStr+=".00"}
		 dStr=workStr.substr(0,workStr.indexOf("."));dNum=dStr-0
		 pStr=workStr.substr(workStr.indexOf("."))
		 while (pStr.length<3){pStr+="0"}

		 //--- Adds comma in thousands place.
		 if (dNum>=1000)
		 {
			dLen=dStr.length
			dStr=parseInt(""+(dNum/1000))+","+dStr.substring(dLen-3,dLen)
		 }

		 //-- Adds comma in millions place.
		 if (dNum>=1000000)
		 {
			dLen=dStr.length
			dStr=parseInt(""+(dNum/1000000))+","+dStr.substring(dLen-7,dLen)
		 }
		 retval = dStr + pStr
		 //-- Put numbers in parentheses if negative.
		 if (nAmount<0) {retval="("+retval+")"}
		 return "$"+retval
	  }

	  function getTaxRate()
	  {
		// Need to get the correct tax rate based upon what State.
		// Get the state the user is shipping to.		
	   /* nStateIDX = document.formSalesOrder.elements["BillingState"].selectedIndex;
		strState = document.formSalesOrder.elements["BillingState"].options[nStateIDX].value;
		nTaxRate = 0.00;
		if ( strState == "MI - Michigan" )
		{
		 // If the selected state is 'MI - Michigan' then return the correct tax
		  nTaxRate = 6.000000;
		}
		return nTaxRate/100;*/
	  }
	  function getShippingRate()
	  {
		// Shipping is a fixed percentage rate
		var nRate = 0.000000/100;
		return nRate;
	  }

	  function updateTotal()
	  {
		var dSubtotal = 0.00;
		var dShipping = 0.00;
		var dTax = 0.00;
		var dTotal = 0.00;

		dTaxRate = getTaxRate();

		var itemQuantity = ["QTY_1_TxTrayLW_DS","QTY_2_TxTrayThumb_DS","QTY_3_TxTrayHW_DS","QTY_4_TxTrayKT_DS","QTY_5_TxTrayLW","QTY_6_TxTrayThumb" , "QTY_7_TxTrayHW" , "QTY_8_TxTrayKT" , "QTY_9_DS_Retrofit" , "QTY_10_DS"];
		var itemTotal = ["TOTAL_1_TxTrayLW_DS","TOTAL_2_TxTrayThumb_DS","TOTAL_3_TxTrayHW_DS","TOTAL_4_TxTrayKT_DS","TOTAL_5_TxTrayLW",	"TOTAL_6_TxTrayThumb" , "TOTAL_7_TxTrayHW" , "TOTAL_8_TxTrayKT" , "TOTAL_9_DS_Retrofit" , "TOTAL_10_DS"];
		var itemPrice = ["PRICE_1_TxTrayLW_DS","PRICE_2_TxTrayThumb_DS","PRICE_3_TxTrayHW_DS","PRICE_4_TxTrayKT_DS","PRICE_5_TxTrayLW",	"PRICE_6_TxTrayThumb" , "PRICE_7_TxTrayHW" , "PRICE_8_TxTrayKT" , "PRICE_9_DS_Retrofit" , "PRICE_10_DS"];

		for(var iCnt=0;iCnt<itemQuantity.length;iCnt++){


			// Get the quantity for item 'Product 3'
			nSelIDX = 0;

			nSelIDX = document.formSalesOrder.elements[itemQuantity[iCnt]].selectedIndex;
			nQty = Number(document.formSalesOrder.elements[itemQuantity[iCnt]].options[nSelIDX].value);
			// Update the line total for this item.
			// Product subtotal = Quantity * Price
			dProdSub = 0.00;
			dProdSub = nQty * document.formSalesOrder.elements[itemPrice[iCnt]].value;
			document.formSalesOrder.elements[itemTotal[iCnt]].value = formatCurrency(dProdSub);

			// Form subtotal
			dSubtotal += dProdSub;
		}

		// Update the TOTAL for the form.
		if ( nQty != 0 )
		{
		  dTax += dProdSub * dTaxRate;
		  dShipping = (getShippingRate()*dSubtotal);
		}

		dTotal = dSubtotal + dTax + dShipping;
		document.formSalesOrder.elements["editSubtotal"].value=formatCurrency(dSubtotal);
//		document.formSalesOrder.elements["editSH"].value=formatCurrency(dShipping);
		document.formSalesOrder.elements["editTax"].value=formatCurrency(dTax);
		document.formSalesOrder.elements["editTotal"].value=formatCurrency(dTotal);
	  }


// @@@@@ SALES ORDER SCRIPTS End @@@@@





EDIT::: Post solved on another forum, problem was with a mispelling in one of the form id's.

This post has been edited by neoseeker191: 10 February 2009 - 08:35 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1