PDA

View Full Version : Use variable instead of number for function input



EUDIS
Oct 29th, 2009, 03:09 PM
Hello

I'm using simpleCart() javascript shopping machine for my page.
The script accepts values in a specific syntax:

onclick="simpleCart.add('name=Some name','price=23.4','quantity=1');"
But because the price of the product is not always the same but comes up after previously made calculations, i want to parse the values in simpleCart() through another function. I have made the following one which gets the price from a textbox (resultAlmires) of a form (Almires), then converts it to american format (. instead of ,) makes it have one decimal only and finally parse it to simpleCart() with the use of a variable.
However it doesn't seem to work:

function addAlmiri() {
var timi = document.Almires.resultAlmires.value;
timi = timi.replace(/\,/,".");
timi = timi.toFixed(1);
simpleCart.add( 'name = Some name' , 'price = timi' , 'quantity = 1' );
}

Any help?

Philip M
Oct 29th, 2009, 04:19 PM
timi = (timi*1).toFixed(1); // timi must be a number, not a string (but is a string after .toFixed() has beeen applied).

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Old Pedant
Oct 29th, 2009, 09:57 PM
Ummm...not quite, Philip.

Unless the simpleCart.add code is *looking* for a non-numeric value and then does an eval() to convert the string to a number, you would want to do:



function addAlmiri()
{
var timi = document.Almires.resultAlmires.value;
timi = parseFloat( timi.replace(/[^\d\.]/g,""); // my preferred way of cleaning numbers
if ( isNaN(timi) ) { alert("Invalid number"); return false; }
timi = timi.toFixed(2);
simpleCart.add( 'name = Some name' , 'price = ' + timi, 'quantity = 1' );
}

EUDIS
Oct 29th, 2009, 10:12 PM
function addAlmiri() {
var timi = document.Almires.resultAlmires.value;
timi = timi.replace(/\,/,".");
timi = (timi*1).toFixed(1);
simpleCart.add( 'name = Sandwich' , price = timi , 'quantity=1' );
}

It does converts it to a number after your change, but still the simplecart.Add() won't accept the values. When it does work the lines in cart look like:
- 1 + Nescafe €2.00 €2.00 Remove

But in this case it looks like:
- 1 + €NaN €NaN Remove

so it's obvious that the script has trouble with the price (timi) input.

EUDIS
Oct 29th, 2009, 10:24 PM
Phillip's way works in terms that the script functions. It does proceed, but it shows NaN instead of a number. The second way does not work at all, i mean script doesn't even go on after i press the button.

Old Pedant
Oct 29th, 2009, 11:22 PM
The code you show isn't the same as either Philip's or mine.

simpleCart.add( 'name = Sandwich' , price = timi , 'quantity=1' );

That will:
(a) assign the value in the JS variable timi the JS variable price
(b) pass that value *ONLY* as the second argument to the add( ) function.

So it would be the same as coding

simpleCart.add( 'name = Sandwich' , 2, 'quantity=1' );

And since it's not passing a "pair" I assume that the add( ) code doesn't know what to do.

************

It's real hard for us to guess what the problem is without seeing what the add( ) function does.

But if your code:


onclick="simpleCart.add('name=Some name','price=23.4','quantity=1');"
works, then I contend that mine would also work.

Let me try something...

EUDIS
Oct 29th, 2009, 11:32 PM
The exact code i'm using now is:



function addAlmiri() {
var timi = document.Almires.resultAlmires.value;
timi = timi.replace(/\,/,".");
timi = (timi*1).toFixed(1);
simpleCart.add( ' name = Sandwich ' , ' price = timi ', ' quantity = 1 ' );
}
</script>


I can pass you the code of simplecart.Add(), though it's kinda long but since you know the language good you will quickly move to the part you think the job is done:



this.add = function () {
/* load cart values if not already loaded */
if( !this.pageIsReady ) {
this.initializeView();
this.update();
}
if( !this.isLoaded ) {
this.load();
this.update();
}

var newItem = new CartItem();

/* check to ensure arguments have been passed in */
if( !arguments || arguments.length === 0 ){
error( 'No values passed for item.');
return;
}
var argumentArray = arguments;
if( arguments[0] && typeof( arguments[0] ) != 'string' && typeof( arguments[0] ) != 'number' ){
argumentArray = arguments[0];
}

newItem.parseValuesFromArray( argumentArray );
newItem.checkQuantityAndPrice();

/* if the item already exists, update the quantity */
if( this.hasItem(newItem) ) {
var id=this.hasItem(newItem);
this.items[id].quantity= parseInt(this.items[id].quantity,10) + parseInt(newItem.quantity,10);
} else {
this.items[newItem.id] = newItem;
}

this.update();
};


this.remove = function( id ){
var tempArray = {};
for( var item in this.items ){
if( item != id ){
tempArray[item] = this.items[item];
}
}
this.items = tempArray;
};


this.empty = function () {
simpleCart.items = {};
simpleCart.update();
};


/******************************************************
checkout management
******************************************************/

this.checkout = function() {
if( simpleCart.quantity === 0 ){
alert("Δεν έχετε προσθέσει κανένα είδος στην παραγγελία σας. \n\nΓια να προβάλετε την παραγγελία σας, επιλέξτε πρώτα κάποια προϊόντα κάνοντας κλικ στο πλήκτρο ΠΑΡΑΓΓΕΛΙΑ που βρίσκεται κάτω από το καθένα.");
error("Cart is empty");
return;
}
switch( simpleCart.checkoutTo ){
case PayPal:
simpleCart.paypalCheckout();
break;
case GoogleCheckout:
simpleCart.googleCheckout();
break;
case Email:
simpleCart.emailCheckout();
break;
default:
simpleCart.customCheckout();
break;
}
};

this.paypalCheckout = function() {

var winpar = "scrollbars,location,resizable,status",
strn = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart" +
"&upload=1" +
"&business=" + this.email +
"&currency_code=" + this.currency,
counter = 1,
itemsString = "";


if( this.taxRate ){
strn = strn +
"&tax_cart=" + this.currencyStringForPaypalCheckout( this.taxCost );
}

for( var current in this.items ){
var item = this.items[current];

var optionsString = "";
for( var field in item ){
if( typeof(item[field]) != "function" && field != "id" && field != "price" && field != "quantity" && field != "name" /*&& field != "shipping"*/) {
optionsString = optionsString + "&" + field + "=" + item[field] ;
}
}
optionsString = optionsString.substring(1);

itemsString = itemsString + "&item_name_" + counter + "=" + item.name +
"&item_number_" + counter + "=" + counter +
"&quantity_" + counter + "=" + item.quantity +
"&amount_" + counter + "=" + this.currencyStringForPaypalCheckout( item.price ) +
"&on0_" + counter + "=" + "Options" +
"&os0_" + counter + "=" + optionsString;
counter++;
}

if( this.shipping() != 0){
itemsString = itemsString + "&item_name_" + counter + "=Shipping" +
"&item_number_" + counter + "=" + counter +
"&quantity_" + counter + "=1" +
"&amount_" + counter + "=" + this.currencyStringForPaypalCheckout( this.shippingCost );
}


strn = strn + itemsString ;
window.open (strn, "paypal", winpar);
};

this.googleCheckout = function() {
if( this.currency != USD && this.currency != GBP ){
error( "Google Checkout only allows the USD and GBP for currency.");
return;
} else if( this.merchantId === "" || this.merchantId === null || !this.merchantId ){
error( "No merchant Id for google checkout supplied.");
return;
}

var form = document.createElement("form"),
counter = 1;
form.style.display = "none";
form.method = "POST";
form.action = "https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/" +
this.merchantId;
form.acceptCharset = "utf-8";

for( var current in this.items ){
var item = this.items[current];
form.appendChild( this.createHiddenElement( "item_name_" + counter, item.name ) );
form.appendChild( this.createHiddenElement( "item_quantity_" + counter, item.quantity ) );
form.appendChild( this.createHiddenElement( "item_price_" + counter, item.price ) );
form.appendChild( this.createHiddenElement( "item_currency_" + counter, this.currency ) );
form.appendChild( this.createHiddenElement( "item_tax_rate_" + counter, this.taxRate ) );
form.appendChild( this.createHiddenElement( "_charset_" , "" ) );

var descriptionString = "";

for( var field in item){
if( typeof( item[field] ) != "function" &&
field != "id" &&
field != "quantity" &&
field != "price" )
{
descriptionString = descriptionString + ", " + field + ": " + item[field];
}
}
descriptionString = descriptionString.substring( 1 );
form.appendChild( this.createHiddenElement( "item_description_" + counter, descriptionString) );
counter++;
}

document.body.appendChild( form );
form.submit();
document.body.removeChild( form );
};



this.emailCheckout = function() {
window.open('cart.html','welcome')

};

this.customCheckout = function() {
return;
};
this.load = function () {
/* initialize variables and items array */
this.items = {};
this.total = 0.00;
this.quantity = 0;

/* retrieve item data from cookie */
if( readCookie('simpleCart') ){
var data = unescape(readCookie('simpleCart')).split('++');
for(var x=0, xlen=data.length;x<xlen;x++){

var info = data[x].split('||');
var newItem = new CartItem();

if( newItem.parseValuesFromArray( info ) ){
newItem.checkQuantityAndPrice();
/* store the new item in the cart */
this.items[newItem.id] = newItem;
}
}
}
this.isLoaded = true;
};



/* save cart to cookie */
this.save = function () {
var dataString = "";
for( var item in this.items ){
dataString = dataString + "++" + this.items[item].print();
}
createCookie('simpleCart', dataString.substring( 2 ), 30 );
};
this.initializeView = function() {
this.totalOutlets = getElementsByClassName('simpleCart_total');
this.quantityOutlets = getElementsByClassName('simpleCart_quantity');
this.cartDivs = getElementsByClassName('simpleCart_items');
this.taxCostOutlets = getElementsByClassName('simpleCart_taxCost');
this.taxRateOutlets = getElementsByClassName('simpleCart_taxRate');
this.shippingCostOutlets = getElementsByClassName('simpleCart_shippingCost');
this.finalTotalOutlets = getElementsByClassName('simpleCart_finalTotal');

this.addEventToArray( getElementsByClassName('simpleCart_checkout') , simpleCart.checkout , "click");
this.addEventToArray( getElementsByClassName('simpleCart_empty') , simpleCart.empty , "click" );

this.Shelf.readPage();

this.pageIsReady = true;

};
this.updateView = function() {
this.updateViewTotals();
if( this.cartDivs && this.cartDivs.length > 0 ){
this.updateCartView();
}
};

this.updateViewTotals = function() {
var outlets = [ ["quantity" , "none" ] ,
["total" , "currency" ] ,
["shippingCost" , "currency" ] ,
["taxCost" , "currency" ] ,
["taxRate" , "percentage" ] ,
["finalTotal" , "currency" ] ];

for( var x=0,xlen=outlets.length; x<xlen;x++){

var arrayName = outlets[x][0] + "Outlets",
outputString;

for( var element in this[ arrayName ] ){
switch( outlets[x][1] ){
case "none":
outputString = "" + this[outlets[x][0]];
break;
case "currency":
outputString = this.valueToCurrencyString( this[outlets[x][0]] );
break;
case "percentage":
outputString = this.valueToPercentageString( this[outlets[x][0]] );
break;
default:
outputString = "" + this[outlets[x][0]];
break;
}
this[arrayName][element].innerHTML = "" + outputString;
}
}
};

this.updateCartView = function() {
var newRows = [],
x,newRow,item,current,header,newCell,info,outputValue,option,headerInfo;

/* create headers row */
newRow = document.createElement('div');
for( header in this.cartHeaders ){
newCell = document.createElement('div');
headerInfo = this.cartHeaders[header].split("_");

newCell.innerHTML = headerInfo[0];
newCell.className = "item" + headerInfo[0];
for(x=1,xlen=headerInfo.length;x<xlen;x++){
if( headerInfo[x].toLowerCase() == "noheader" ){
newCell.style.display = "none";
}
}
newRow.appendChild( newCell );

}
newRow.className = "cartHeaders";
newRows[0] = newRow;

/* create a row for each item in the cart */
x=1;
for( current in this.items ){
newRow = document.createElement('div');
item = this.items[current];

for( header in this.cartHeaders ){

newCell = document.createElement('div');
info = this.cartHeaders[header].split("_");

switch( info[0].toLowerCase() ){
case "total":
outputValue = this.valueToCurrencyString(parseFloat(item.price)*parseInt(item.quantity,10) );
break;
case "increment":
outputValue = this.valueToLink( "+" , "javascript:;" , "onclick=\"simpleCart.items[\'" + item.id + "\'].increment();\"" );
break;
case "decrement":
outputValue = this.valueToLink( "-" , "javascript:;" , "onclick=\"simpleCart.items[\'" + item.id + "\'].decrement();\"" );
break;
case "remove":
outputValue = this.valueToLink( "Αφαίρεση" , "javascript:;" , "onclick=\"simpleCart.items[\'" + item.id + "\'].remove();\"" );
break;
case "price":
outputValue = this.valueToCurrencyString( item[ info[0].toLowerCase() ] ? item[info[0].toLowerCase()] : " " );
break;
default:
outputValue = item[ info[0].toLowerCase() ] ? item[info[0].toLowerCase()] : " ";
break;
}

for( var y=1,ylen=info.length;y<ylen;y++){
option = info[y].toLowerCase();
switch( option ){
case "image":
case "img":
outputValue = this.valueToImageString( outputValue );
break;
case "input":
outputValue = this.valueToTextInput( outputValue , "onchange=\"simpleCart.items[\'" + item.id + "\'].set(\'" + outputValue + "\' , this.value);\"" );
break;
case "div":
case "span":
case "h1":
case "h2":
case "h3":
case "h4":
case "p":
outputValue = this.valueToElement( option , outputValue , "" );
break;
case "noheader":
break;
default:
error( "unkown header option: " + option );
break;
}

}
newCell.innerHTML = outputValue;
newCell.className = "item" + info[0];
newRow.appendChild( newCell );
}
newRow.className = "itemContainer";
newRows[x] = newRow;
x++;
}



for( current in this.cartDivs ){

/* delete current rows in div */
var div = this.cartDivs[current];
while( div.childNodes[0] ){
div.removeChild( div.childNodes[0] );
}

for(var j=0, jLen = newRows.length; j<jLen; j++){
div.appendChild( newRows[j] );
}


}
};

this.addEventToArray = function ( array , functionCall , theEvent ) {
for( var outlet in array ){
var element = array[outlet];
if( element.addEventListener ) {
element.addEventListener(theEvent, functionCall , false );
} else if( element.attachEvent ) {
element.attachEvent( "on" + theEvent, functionCall );
}
}
};


this.createHiddenElement = function ( name , value ){
var element = document.createElement("input");
element.type = "hidden";
element.name = name;
element.value = value;
return element;
};

Old Pedant
Oct 29th, 2009, 11:34 PM
Ahhh...you know, if you would TURN ON JavaScript debugging, you'd find silly mistakes like mine immediately.

I was missing a right paren ) in this line:

/g,"") ); // needs *TWO* right parens!

Here's the quick and dirty test page I created:


<html>
<head>
<script>
function cart()
{
this.add = function( p1, p2, p3 )
{
alert(p1 + "\n" + p2 + "\n" + p3);
}
}
var simpleCart = new cart();

function simpleAdd()
{
simpleCart.add( 'name = Some name' , 'price = 23.4', 'quantity = 1' );
}
function formAdd()
{
var timi = document.Almires.resultAlmires.value;
timi = parseFloat( timi.replace(/[^\d\.]/g,"") ); // my preferred way of cleaning numbers
if ( isNaN(timi) ) { alert("Invalid number"); return false; }
timi = timi.toFixed(2);
simpleCart.add( 'name = Some name' , 'price = ' + timi, 'quantity = 1' );
}
</script>
</head><body>
<form name="Almires">
<input name="resultAlmires">
<br/>
<input type=button value="test 1" onclick="simpleAdd()">
<input type=button value="test 2" onclick="formAdd()">
</form>
</body></html>

Old Pedant
Oct 29th, 2009, 11:39 PM
Yes, the code makes sense, but it isn't complete. The key to understanding it is this line:


newItem.parseValuesFromArray( argumentArray );

(and probably the next line, too), but that function isn't in the source code you showed.

Still, I think you will find that adding the right paren I showed will fix my code.

Clearly the code you are using can't work, as is.

Old Pedant
Oct 29th, 2009, 11:44 PM
I just noticed one thing: Philip's code is converting a comma (,) into a period (.).

If in your country you use , as the decimal point indicator, then you *will* need Philip's change, as well, to handle numbers such as "23,4" and "12,0".

So that's easy: Use both his code and mine.


function formAdd()
{
var timi = document.Almires.resultAlmires.value;
timi = timi.replace( /\,/, "." );
timi = parseFloat( timi.replace(/[^\d\.]/g,"") ); // my preferred way of cleaning numbers
if ( isNaN(timi) ) { alert("Invalid number"); return false; }
timi = timi.toFixed(2);
simpleCart.add( 'name = Some name' , 'price = ' + timi, 'quantity = 1' );
}


Because you gave the working example as

onclick="simpleCart.add('name=Some name','price=23.4','quantity=1');" I would *guess* that you don't use comma in this way.

But just in case.

EUDIS
Oct 30th, 2009, 12:09 AM
still, it doesn't work :(

I really can't make it to work - i have tried all possible changes.

Anyway... I wanted to post the full code since some part is missing like Phillip said but it's too long and the forum doesn;t let me. You can see the full code in http://simplecartjs.com/download.html (it's the simplecart.js file), where i also got it.

Thank you so much guys i really appreciate the time you spend over my issue

Old Pedant
Oct 30th, 2009, 12:19 AM
Show your <form>...</form> code.

That is, only the part of your page between the <form> and </form> tags. And if you have many items in there, you can just show one sample item instead of all of them.

Old Pedant
Oct 30th, 2009, 12:27 AM
You are doing something wrong, because when I modified the "index.html" from that download page to use a <form> as you seem to have and include the function as I coded it for you, it worked perfectly.

(Well, it looked ugly, but it worked.)

Here is the modified "index.html" file, with the *ONLY* changes I made in red:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>simpleCart(JS) 2.0 Demo </title>

<script type="text/javascript" src="simpleCart.js"></script>
<script type="text/javascript">
simpleCart.email = "[email protected]";
simpleCart.checkoutTo = PayPal;
simpleCart.currency = USD;
simpleCart.taxRate = 0.08;
simpleCart.shippingQuantityRate = 1.00;

simpleCart.cartHeaders = ["Thumb_image_noHeader", "Name" , "Size_input_div_div", "Price" , "decrement_noHeader" , "Quantity", "increment_noHeader", "remove_noHeader", "Total" ];

function formAdd()
{
var timi = document.Almires.resultAlmires.value;
timi = parseFloat( timi.replace(/[^\d\.]/g,"") ); // my preferred way of cleaning numbers
if ( isNaN(timi) ) { alert("Invalid number"); return false; }
timi = timi.toFixed(2);
simpleCart.add( 'name=Some name','price=' + timi, 'quantity=1' );
}


</script>

<style >

.itemContainer{
width:100%;
float:left;
}

.itemContainer div{
float:left;
margin: 5px 20px 5px 20px ;
}

.itemContainer a{
text-decoration:none;
}

.cartHeaders{
width:100%;
float:left;
}

.cartHeaders div{
float:left;
margin: 5px 20px 5px 20px ;
}


</style>
<link rel="stylesheet" href="main.css" type="text/css" media="screen" />
</head>
<body>
<p>
Cart: <span class="simpleCart_total"></span> (<span class="simpleCart_quantity"></span> items)
<br />
<a href="javascript:;" class="simpleCart_empty">empty cart</a>
<br />
</p>


<ul>
<li class="simpleCart_shelfItem">
<h2 class="item_name">Zebra</h2>
<img class="item_thumb" src="e.png" />
<span class="item_price">$187.95</span>
<select class="item_Size">
<option value="Small">Small</option>
<option value="Medium">Medium</option>
<option value="Large">Large</option>
</select>
<input type="hidden" class="item_shipping" value="20" />
<input type="text" class="item_quantity" value="1" />
<input type="button" class="item_add" value="add to cart" />
</li>


<li class="simpleCart_shelfItem">
<h2 class="item_name">Cow</h2>
<img class="item_thumb" src="e.png" />
<span class="item_price">$18.00</span>
<select class="item_Size">
<option value="Tiny">Tiny</option>
<option value="Medium">Medium</option>
<option value="Bull">Bull</option>
</select>
<input type="text" class="item_quantity" value="1" />
<input type="button" class="item_add" value="add to cart" />
</li>



<li>
<form name="Almires">
Put value here: <input name="resultAlmires">
<br/>
<input type=button value="Then test" onclick="formAdd()">
</form> </li>
</ul>
<div class="simpleCart_items" >
</div>
<br />
SubTotal: <span class="simpleCart_total"></span> <br />
Tax: <span class="simpleCart_taxCost"></span> <br />
Shipping: <span class="simpleCart_shippingCost"></span> <br />
-----------------------------<br />
Final Total: <span class="simpleCart_finalTotal"></span> <br />

<a href="javascript:;" class="simpleCart_checkout">checkout</a>
</body>
</html>

EUDIS
Oct 30th, 2009, 01:15 AM
Ok, here it is.

I'm posting you 3 files: crepes.html, salads.html and cart.html. You also need simplecart.js but you already got it. Salads.html works fine. Crepes.html is the problematic one. I have translated a few lines of text in english so can use the files, so:

In salads, there are two products - in this case salad 1 and salad 2 and a button "order" below them Of course you can't see it since you dont have the image file but still it works. When you click it, you can see the "items" and "total" lines updating and increasing by the salads' price.

In crepes.html the thing goes in a different way. You gotta "built" your crepe by selecting ingredients and after you do this you hit the "order" button. So i use checkboxes. Use the "salty" radio to reveal the ingredients and then select one or two of them (i left cheese and ham for you to test it). You can see the total crepe price in textfield below them, but when you click the "order" button the "items" and "total" lines won't update like in previous case.

This is what i;ve been trying to do.

File 1: salads.html


<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253" />
<script type="text/javascript" src="simpleCart.js"></script>
</head>

<body>
<div id="header">
<h1>&nbsp;</h1>
</div>
<div id="container-top"></div>
<div id="container">
<div id="left">
<div id="left-top"></div>
<div id="left-centre">
<h1>Μενού</h1>
<h2><br>
Order</h2>
<p>
Items: <span class="simpleCart_quantity"></span></span></span><br>
Total: <span class="simpleCart_total"></span></span></span><br>
</p>
<p>
<a href="javascript:;" class="simpleCart_checkout">Checkout</a><br>
<a href="javascript:;" class="simpleCart_empty">Erase order</a>
</p>
</div>
</div>
<div id="right">
<div id="tabs">
<ul>
<li><div class="tab-active"></div></li>
</ul>
</div>
<div id="right-top"></div>
<div id="right-centre">
<table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr class="style28">
<td width="39%">
<b>Salad 1</b>
<b></b></td>
<td width="61%"><b>€ 3,50 </b></td>
</tr>
<tr>
<td colspan="2" class="style35"><b>Ντομάτα, αγγουράκι, κρεμμύδι, φέτα, ελιές, ελαιόλαδο </b></td>
</tr>
<tr>
<td height="26"><a href="javascript:;" onclick="simpleCart.add( 'name=Salad 1' ,
'price=3.5' , 'quantity=1' );"><img src="images/button_paraggelia.gif" width="80" height="20" border="0"/></a></td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="26"></td>
<td></td>
</tr>
<tr class="style28">
<td class="style38">Salad 2</td>
<td><b class="style38">€ 2,70 </b></td>
</tr>
<tr class="style35">
<td colspan="2"><b>Ψιλοκομμένο μαρούλι, ξύδι, ελαιόλαδο </b></td>
</tr>
<tr>
<td height="26"><a href="javascript:;" onclick="simpleCart.add( 'name=Salad 2' ,
'price=2.7' , 'quantity=1' );"><img src="images/button_paraggelia.gif" width="80" height="20" border="0"/></a></td>
<td>&nbsp;</td>
</tr>
</table>
</body>
</html>


File 2: crepes.html


<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253" />
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="simpleCart.js"></script>
<script language="JavaScript" type="text/JavaScript">
<!--
function hidediv_glykia() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideshow_glykia').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideshow_glykia.visibility = 'hidden';
}
else { // IE 4
document.all.hideshow_glykia.style.visibility = 'hidden';
}
}
}
function hidediv_almiri() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideshow_almiri').style.visibility = 'hidden';
}
else {
if (document.layers) { // Netscape 4
document.hideshow_almiri.visibility = 'hidden';
}
else { // IE 4
document.all.hideshow_almiri.style.visibility = 'hidden';
}
}
}

function showdiv_glykia() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideshow_glykia').style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideshow_glykia.visibility = 'visible';
}
else { // IE 4
document.all.hideshow_glykia.style.visibility = 'visible';
}
}
}
function showdiv_almiri() {
if (document.getElementById) { // DOM3 = IE5, NS6
document.getElementById('hideshow_almiri').style.visibility = 'visible';
}
else {
if (document.layers) { // Netscape 4
document.hideshow_almiri.visibility = 'visible';
}
else { // IE 4
document.all.hideshow_almiri.style.visibility = 'visible';
}
}
}
function showAlmiri() {
hidediv_glykia();
showdiv_almiri();
}
function showGlykia() {
hidediv_almiri();
showdiv_glykia();

}

//-->
</script>

<script language="JavaScript" type="text/JavaScript">
function calcGlykies(amountGlykies) {
var totalGlykies = .8;
if (document.Glykies.sokolata.checked) { totalGlykies=totalGlykies+.8 }
if (document.Glykies.mpiskoto.checked) { totalGlykies=totalGlykies+.4 }
if (document.Glykies.leuki.checked) { totalGlykies=totalGlykies+.8 }
if (document.Glykies.gemista.checked) { totalGlykies=totalGlykies+.7 }
if (document.Glykies.softkings.checked) { totalGlykies=totalGlykies+.7 }
totalGlykies = totalGlykies.toFixed(2);
totalGlykies = totalGlykies.replace(/\./,",");
document.Glykies.resultGlykies.value = totalGlykies;
}
function calcAlmires(amountAlmires) {
var totalAlmires = .8;
if (document.Almires.edam.checked) { totalAlmires=totalAlmires+.4 }
if (document.Almires.zampon.checked) { totalAlmires=totalAlmires+.5 }
totalAlmires = totalAlmires.toFixed(2);
totalAlmires = totalAlmires.replace(/\./,",");
document.Almires.resultAlmires.value = totalAlmires;
}
</script>

<script language="JavaScript" type="text/JavaScript">
function addAlmiri() {
var timi = document.Almires.resultAlmires.value;
timi = timi.replace(/\,/,".");
timi = parseFloat( timi.replace(/[^\d\.]/g,"") );
timi = timi.toFixed(2);
simpleCart.add( ' name = Κρέπα αλμυρή ' , 'price = ' + timi, ' quantity = 1 ' );
}
</script>

</head>

<body onload="showGlykia();">
<div id="container">
<div id="left">
<div id="left-top"></div>
<div id="left-centre">
<h1>Μενού</h1>
<h2><br>
Παραγγελία</h2>
<p> Items: <span class="simpleCart_quantity"></span><br>
Total: <span class="simpleCart_total"></span><br>
</p>
<p> <a href="javascript:;" class="simpleCart_checkout">Checkout</a><br>
<a href="javascript:;" class="simpleCart_empty">Erase order</a></p>
</div>
</div>
<div id="right">
<div id="tabs">
<ul>
<li><div class="tab-active"></div></li>
</ul>
</div>
<div id="right-top"></div>
<div id="right-centre">
<h1>Μενού &gt; Κρέπες </h1>
<p>
</p>
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td width="17%"><span class="style24">
<input name="type" type="radio" value="almiri" onclick="showAlmiri();"/>
<span class="style26">Salty</span></span></td>
<td width="17%" class="style24">
<input name="type" type="radio" value="glukia" checked="checked" onclick="showGlykia();"/>
<span class="style25">Γλυκιά</span></td>
<td width="17%">&nbsp;</td>
<td width="17%">&nbsp;</td>
<td width="32%">&nbsp;</td>
</tr>
</table>
<p>
</p>

<div id="hideshow_glykia" style="position:relative; width:528px; height:279px; z-index:1; left: 0px; top: -20px;">
<FORM name="Glykies">
<table width="100%" border="0" cellspacing="0" cellpadding="5">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="40%"><span class="style19"><div id="hideshow_glykia"><input type="checkbox" name="sokolata" value="checkbox" onClick="calcGlykies();" />Πραλίνα σοκολάτα (0,80) </div></span></td>
<td width="60%"><span class="style19"><div id="hideshow_glykia"><input type="checkbox" name="mpiskoto" value="checkbox" onClick="calcGlykies();" />Τριμμένο μπισκότο (0,50) </div></span></td>
</tr>
<tr>
<td><span class="style19"><input type="checkbox" name="leuki" value="checkbox" onClick="calcGlykies();" />Λευκή σοκολάτα(0,80) </span></td>
<td><span class="style19"><input type="checkbox" name="gemista" value="checkbox" onClick="calcGlykies();" />Γεμιστά Παπαδοπούλου (0,80) </span></td>
</tr>
<tr>
<td><span class="style19"><input type="checkbox" name="softkings" value="checkbox" onClick="calcGlykies();" />Soft Kings (0,70) </span></td>
</tr>
<tr>
<td><img src="images/button_paraggelia.gif" width="80" height="20" /></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="style25">Φύλλο κρέπας: 1,00€ + επιλεγμένα υλικά =
<input name="resultGlykies" type="text" size="8" readonly="readonly" class="style25" value="0,80">
EUR </td>
</tr>
</table>
</FORM>
<p> <br />
</div>

<div id="hideshow_almiri" style="position:relative; width:528px; height:279px; z-index:1; left: -17px; top: -299px;">
<FORM name="Almires">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td width="3%">&nbsp;</td>
<td width="37%">&nbsp;</td>
<td width="57%">&nbsp;</td>
<td width="3%">&nbsp;</td>
</tr>

<tr>
<td>&nbsp;</td>
<td><span class="style19"><input type="checkbox" name="edam" value="checkbox" onClick="calcAlmires();" />Cheese (0,50) </span></td>
<td><span class="style19"><input type="checkbox" name="zampon" value="checkbox" onClick="calcAlmires();" />Ham (0,50) </span></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><a href="javascript:;" onclick="addAlmiri();"><img src="images/button_paraggelia.gif" width="80" height="20" border="0"/></a></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td colspan="2" class="style25">Φύλλο κρέπας: 1,00€ + επιλεγμένα υλικά =
<input name="resultAlmires" type="text" size="15" readonly="readonly" class="style25" value="0,80">
EUR </td>
<td>&nbsp;</td>
</tr>
</table>
</FORM>
<p>

</div></div>

</div>
<div class="clear"></div>
</div>
<div id="container-bottom"></div>
<div id="footer-top"></div>
<div id="footer-centre">
<p><span class="style1">&copy; 2009 Lukulos snack bar </span></p>
</div>
<div id="footer-bottom"></div>
</body>

</html>


File 3: cart.html


<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253" />
<script type="text/javascript" src="simpleCart.js"></script>
<script language="JavaScript" type="text/JavaScript">
simpleCart.cartHeaders = ["decrement_noHeader" , "Quantity_noHeader", "increment_noHeader", "Name_noHeader" , "Price_noHeader" , "Total_noHeader", "remove_noHeader" ];
function gotomenu() {
window.location = "menu.html"
}
</script>
</head>

<body>
<div class="simpleCart_items"></div>


<p>Total: <span class="simpleCart_total"></span> <br />
Items: <span class="simpleCart_quantity"></span><br />
</body>

</html>

Old Pedant
Oct 30th, 2009, 01:40 AM
LOL!!!

You will *LOVE* this!

The ONLY problem is that you had *SPACES* around the word " price "!!!

The code in there takes your term, such as " price = 33 " and splits in on the "=" and then checks to see if the word is "price". But IT WAS NOT! It was " price "!

Now, we could fix that code, but it's easier to fix yours:

When I changed your code to get rid of the extra spaces, it worked!


simpleCart.add( 'name=Κρέπα αλμυρή' , 'price=' + timi, 'quantity=1' );

EUDIS
Oct 30th, 2009, 01:50 AM
I FREAKING can't believe this!!! All this trouble just to realize it's a matter of a .... space hahahahaha

Thanks so much dude