Hent data i cookie
HejMit problem er, at hvis jeg har mere end en linie i min cookie, så kan jeg ikke lægge alle data over i en mysql database. Det er kun den sidste linie, som kommer i \"Form\" felterne nedenfor i scriptet. Jeg har hørt, at det muligvis skulle være noget i Javascriptet der skal ændres, og derfor prøver jeg her.
Mit script ser sådan ud:
<form action=bestil_vare.php method=GET>
<script LANGUAGE=\"JavaScript\">
// alterError - fixes a rounding bug in Netscape 2
function alterError(value) {
if (value<=0.99) {
newPounds = \'0\';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence=\'0\'+newPence;
newString = newPounds + \'.\' + newPence;
return (newString);
}
// showItems () - creates a table of items in the basket and
// creates the start of a form which sets information for
// basket items.
function showItems() {
index = document.cookie.indexOf(\"TheBasket\");
countbegin = (document.cookie.indexOf(\"=\", index) + 1);
countend = document.cookie.indexOf(\";\", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln(\'<TR><TD><b><font size=-1>Vare</font></b></TD><TD><b><font size=-1>Antal</font></b></TD><TD><b><font size=-1>Pr.Stk</font></b></TD><td><b><font size=-1>Ialt</font></b></td></TR>\');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == \'[\') {
thisitem = 1;
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == \']\') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
document.write(\'<tr><td>\'+theitem+\'</td>\');
document.writeln(\'<td align=right>\'+thequantity+\'</td><td align=right>\'+theprice+\'</td><td align=right>\'+alterError(itemtotal)+\'</td></tr>\');
document.writeln(\'<INPUT TYPE=\"hidden\" NAME=\"Bestilling\" VALUE=\"\'+theitem+\'\" SIZE=\"40\">\');
document.writeln(\'<INPUT TYPE=\"hidden\" NAME=\"Antal\" VALUE=\"\'+thequantity+\'\" SIZE=\"40\">\');
document.writeln(\'<INPUT TYPE=\"hidden\" NAME=\"Prstk\" VALUE=\"\'+theprice+\'\" SIZE=\"40\">\');
document.writeln(\'<INPUT TYPE=\"hidden\" NAME=\"Ialt\" VALUE=\"\'+alterError(itemtotal)+\'\" SIZE=\"40\">\');
} else if (fulllist.substring(i,i+1) == \'|\') {
if (thisitem==1) theitem = fulllist.substring(itemstart, i);
if (thisitem==2) theprice = fulllist.substring(itemstart, i);
thisitem++;
itemstart=i+1;
}
}
document.writeln(\'<tr><td colspan=3><b>Total</b></td><td align=right>\'+alterError(totprice)+\'</td></tr>\');
document.writeln(\'<INPUT TYPE=\"hidden\" NAME=\"Prisaltialt\" VALUE=\"\'+alterError(totprice)+\'\" SIZE=\"40\">\');
document.writeln(\'</TABLE>\');
}
</script>
<!--webbot bot=\"HTMLMarkup\" TAG=\"XBOT\" startspan --></SCRIPT><!--webbot bot=\"HTMLMarkup\" endspan -->
<div align=\"center\"><center><h2>Bestil varer</h2>
</center></div><!-- call showItems to show items in basket -->
<script LANGUAGE=\"JavaScript\">
showItems();
</script>
<div align=\"center\"><center><p><br>
</center></div><div align=\"center\"><center><p><input type=\"submit\" value=\"bestil\" name=\"send\"></p>
</center></div>
</form>
Pluth
