Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][JavaScript] Jak pobrać wartość z pola i zastąpić nią atrybut value
amii
post 14.07.2010, 12:58:52
Post #1





Grupa: Zarejestrowani
Postów: 728
Pomógł: 76
Dołączył: 12.06.2009

Ostrzeżenie: (0%)
-----


Mam koszyk a tam pole input zdefiniowane jako ilość w którą użytkownik może wpisać jakąś wartość. Następnie jest przycisk przelicz gdzie powinna być przeliczana ilość produktów * cena.
I tu jest problem gdyż pole ilość jest pobierane z bazy danych co zrobić aby w przypadku wpisania innej wartości przez użytkownika ta wartość z bazy została nadpisana.
Poniżej link -> http://alkomatydowodowe.pl/index.php?p=cart (trzeba wrzucić jakiś produkt do koszyka)
Poniżej kod:


  1. $html .= '<table cellspacing="2" cellpadding="0" align="center" style="margin-top:10px;">';
  2. $html .= '<form name="cart_recount" method="POST" action="index.php">';
  3. $html .= '<input type="HIDDEN" name="p" value="cart">';
  4. $html .= '<input type="HIDDEN" name="recount" value="true">';
  5. $html .= '<tr>';
  6.  
  7. // pozycje
  8. $query = mysql_query("SELECT *,cart.id AS item FROM cart LEFT JOIN product ON cart.pid = product.id WHERE session='".session_id()."' LIMIT 0,10;");
  9.  
  10.  
  11. while($cartitem = mysql_fetch_assoc($query))
  12. {
  13.  
  14. $html .= '<td style="width:40px; height:30px; background-color:#ffffff; border-style:solid; border-color:#ececec; border-width:1px; text-align:center; vertical-align:middle;" class="cart_main_item">
  15.  
  16. <input id="pole" type="TEXT" name="quantity_'.$cartitem['id'].'" value="'.$cartitem['quantity'].'" //ti jest wartosc wpisywana w pole ilość
  17. class="cart_main_item" style="border-style:none; background-color:#ffffff; width:40px; padding:0px 0px 0px 0px; text-align:center;"></td>';
  18.  
  19.  
  20.  
  21. $html .= '<td style="width:80px; height:30px; background-color:#ffffff; border-style:solid; border-color:#ececec; border-width:1px; text-align:center; vertical-align:middle; font-weight:bold;" class="cart_main_item">'.number_format(($cartitem['quantity']*$cartitem['pricewithtax_discount']),2,',',' ').'zł<br>z VAT</td>';
  22. $html .= '<td style="width:25px; height:30px; background-color:#ffffff; border-style:solid; border-color:#ececec; border-width:1px; text-align:center; vertical-align:middle;" class="cart_main_item"><A href="index.php?p=cart&delete='.$cartitem['item'].'"><img src="layout/'.$style.'/delete.png" alt="" title="" border="0" style="width:20px; height:20px;"></a></td>';
  23. $html .= '</tr>';
  24.  
  25. $sum += ($cartitem['quantity']*$cartitem['pricewithtax_discount']);
  26. }
  27. // podusmowenie cen
  28. $html .= '</form>';
  29. $html .= '<tr>';
  30. $html .= '<td style="width:25px; height:30px; background-color:#ffffff; border-style:solid; border-color:#ffffff; border-width:1px; text-align:left; vertical-align:middle;" class="cart_main_top" colspan="6">';
  31. $html .= '<img onClick="document.cart_recount.submit();" src="layout/'.$style.'/cart_recount_off.png" onMouseOver="this.src='."'layout/".$style."/cart_recount_on.png'".';" onMouseOut="this.src='."'layout/".$style."/cart_recount_off.png'".';" alt="" title="" border="0" style="cursor:pointer;">'; //tu jest przycisk do przeliczania cena*ilosc
  32. $html .= '<img src="layout/'.$style.'/cart_recount_on.png" alt="" title="" border="0" style="display:none;">';
  33. $html .= '</td>';
  34. $html .= '<td style="width:80px; height:30px; background-color:#ececec; border-style:solid; border-color:#dddddd; border-width:1px; text-align:center; vertical-align:middle; font-weight:bold;" class="cart_main_top">'.number_format($sum,2,',',' ').'zł<br>z VAT</td>';
  35. $html .= '<td style="width:25px; height:30px; background-color:#ffffff; border-style:solid; border-color:#ffffff; border-width:1px; text-align:center; vertical-align:middle;" class="cart_main_top">&nbsp;</td>';
  36. $html .= '</tr>';
  37. $html .= '</table>';


--------------------
gry flash online
Dobry hosting i tanie odnowienia domen firma: masternet.
Zarabianie bez wysiłku na domenach bez ruchu: prolink.
Go to the top of the page
+Quote Post
t4keda
post 14.07.2010, 14:00:32
Post #2





Grupa: Zarejestrowani
Postów: 57
Pomógł: 10
Dołączył: 14.10.2009

Ostrzeżenie: (0%)
-----


musisz dodać warunek, który będzie sprawdzał czy istnieje zmienna $_POST['ilosc'] (name pola ilość) i jeśli istnieje to wstawiasz jego zawartość, a jeśli nie to wstawiasz ilość podaną przy dodaniu do koszyka
Go to the top of the page
+Quote Post
amii
post 14.07.2010, 14:39:21
Post #3





Grupa: Zarejestrowani
Postów: 728
Pomógł: 76
Dołączył: 12.06.2009

Ostrzeżenie: (0%)
-----


Ale ta zmienna zawsze istnieje bo jest domyślnie czytana z bazy. Jakieś inne pomysły ?


--------------------
gry flash online
Dobry hosting i tanie odnowienia domen firma: masternet.
Zarabianie bez wysiłku na domenach bez ruchu: prolink.
Go to the top of the page
+Quote Post
t4keda
post 14.07.2010, 15:14:25
Post #4





Grupa: Zarejestrowani
Postów: 57
Pomógł: 10
Dołączył: 14.10.2009

Ostrzeżenie: (0%)
-----


jeśli pobieranie danych z bazy odbywa się przy każdym przeładowaniu/odświeżeniu/przeliczeniu koszyka, to ta zmienna PRZED wczytaniem z bazy nie istnieje (no chyba, że jest gdzieś w zmiennej sesyjnej)
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 12:04