Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [js] przesłanie danych z array
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
verbos
Mam problem polegający na tym, że nie mogę przesłać danych z tablicy, którą wypisuje funkcja:
[xml:1:bef92ec28e]
<script LANGUAGE="JavaScript">
<!--

function deciCorr(value) {
if (value<=0.99) {
newDoll = '0';
} else {
newDoll = parseInt(value);
}
newCents = parseInt((value+.0008 - newDoll)* 100);
if (eval(newCents) <= 9) newCents='0'+newCents;
newString = newDoll + '.' + newCents;
return (newString);
}

function showItems() {
index = document.cookie.indexOf("ShopCart");
countstart = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countstart, countend);
totprice = 0;


document.writeln('<table width="100%" border="1" cellspacing="0" cellpadding="3" bordercolor="black" bordercolorlight="black" bordercolordark="black">');
document.writeln('<tr><td width="50%"><font class="titleCart">Nazwa towaru</td><td><center><font class="titleCart">Ilo&para;ć</td><td><center><font class="titleCart">Cena Jednostkowa</td><td align="right"><font class="titleCart">Razem</td></tr>');

itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+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 +0 ;
itemlist=itemlist+1;



document.writeln('<tr><td>'+theitem+'</td><td align="right"><center>'+thequantity+'</td><td align="right"><center>'+theprice+'</td><td align="right">'+deciCorr(itemtotal)+'</td></tr>');
document.writeln('<input type="hidden" name="item[]" value="'+theitem+'">');
document.writeln('<input type="hidden" name="quantity[]" value="'+thequantity+'">');
document.writeln('<input type="hidden" name="priceeach[]" value="'+theprice+'">');
document.writeln('<input type="hidden" name="totalcost[]" value="'+deciCorr(itemtotal)+'">');



} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;

} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}

document.writeln('<tr><td colspan="3"><b>Suma netto</b></td><td align="right">'+deciCorr(totprice)+'</td></tr>');





tax_eq = 22 / 100;
tax_am = totprice * tax_eq;
document.writeln('<tr><td colspan="3"><b>VAT</b></td><td align="right">'+deciCorr(tax_am)+'</td></tr>');
totprice = totprice + tax_am;

document.writeln('<input type="hidden" name="tax_calc" value="'+deciCorr(tax_am)+'">');


document.writeln('<input type="hidden" name="totalxfreight" value="'+deciCorr(totprice)+'">');




document.writeln('<tr><td colspan=3><b>Do Zapłaty brutto</b></td><td align=right>PLN <input type="text" size="5" name="total" value="'+deciCorr(totprice)+'" disabled></td></tr>');
document.writeln('</table>');

}
//-->
</script>
[/xml:1:bef92ec28e]
odczytać się odczytuje wspaniale, lecz nie mogę tego przesłać dalej do php. Jedyne co wypisuje mi to:
item : Array
quantity : Array
priceeach : Array
totalcost : Array
tax_calc : 26.40
totalxfreight : 146.40
czyli problem tkwi w przekazaniu tego:
[xml:1:bef92ec28e]
document.writeln('<tr><td>'+theitem+'</td><td align="right"><center>'+thequantity+'</td><td align="right"><center>'+theprice+'</td><td align="right">'+deciCorr(itemtotal)+'</td></tr>');
document.writeln('<input type="hidden" name="item[]" value="'+theitem+'">');
document.writeln('<input type="hidden" name="quantity[]" value="'+thequantity+'">');
document.writeln('<input type="hidden" name="priceeach[]" value="'+theprice+'">');
document.writeln('<input type="hidden" name="totalcost[]" value="'+deciCorr(itemtotal)+'">');
[/xml:1:bef92ec28e]
poprzez pentlę for.
Czy możecie powiedzieć gdzie robię błąd?
Pozdrawiam
verbos
wiem, że sprawa gdzieś powinna się rozbić o linie:

Kod
   document.writeln('<input type="hidden" name="item1" value="'+theitem+'">');

   document.writeln('<input type="hidden" name="quantity1" value="'+thequantity+'">');

   document.writeln('<input type="hidden" name="priceeach1" value="'+theprice+'">');

   document.writeln('<input type="hidden" name="totalcost1" value="'+deciCorr(itemtotal)+'">');



bo jak wywale [] po nazwach, tak jak tu, to przekazuje mi tak jak sobie tego życzę nazwy ilości itp, ale tylko ostatnio dadanego elementu do koszyka... i teraz chce to jakoś zautomatyzować jakąś pentelką, żeby mi robił tak jak tu już zacząłem, czyli :

item1
quantity1
priceeach1
totalcost1
item2
quantity2
priceeach2
totalcost2

itd...

ale nie bardzo wiem jak go zmusić do tego, aby realizował sam inputy automatycznie...
verbos
Dzięki wielkie... jakoś sobie poradziłem...
szkoda, że nie było odzewu
e-Gandalf
szkoda, ze nie pomyslales o zminimalizowaniu przykladu. Ja naprawde chetnie pomoge, ale nie mam sily grzebac sie w dziesiatkach linii kodu, zeby znalezc blad logiczny lub semantyczny w linii 688.
verbos
spoko.... snitch.gif dzięki....
tam błędu raczej nie było.....
tzn skrypt przekazywał tablicę, a trzeba było dostawić pętelkę i pokolei wywalać dane do php.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.