
Originariamente Scritto da
cali1981
Ciao Elisa, credo che nello script
js che hai postato manchi qualche parte importante, in ogni caso sei sicura che richiamando la pagina addProduct.
asp con un productId valido questa funzioni? Prova a richiamarla così:
addProduct.asp?productId=123
sostituendo a 123 un id valido e vedi che ti dice!
Ciao,
innanzitutto grazie per l'aiuto 
Allora ho fatto la prova e mi sono accorta dei piccoli errori che infatti bloccavano il recupero productId, ho corretto e adesso l'inserimento onthefly avviene correttamente...ma... non effettua, come invece nello script originale, il calcolo del totale
Ho strutturato la pagina principale dove c'è il carrello in questo modo:
Codice:
<span>I Nostri Prodotti in vetrina</span></h2>
<%
RecordsPerPagina = 9
page = Request("page")
if page="" then page = 1
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM " &strDbTable& "prodotti WHERE p_promozione = 1 AND p_status = 1 ORDER BY p_codice;" 'estraggo i prodotti in promozione
objRS.Open strSQL, DFCon, 1, 1
TotalRecords = objRS.RecordCount
If TotalRecords = 0 then 'nessun dato inserito
%>
<p>Nessun dato inserito</p>
<%
Else
objRS.PageSize = RecordsPerPagina
objRS.AbsolutePage = page
' c = 0
%>
<div id="products">
<%
For i = 1 to RecordsPerPagina
If Not objRS.EOF Then
c=objRS("idProdotto")
%>
<!-- DIV FOR A PRODUCT -->
<div class="product_container">
<div id="slidingProduct<%=c%>">
<table width="100%" border="0">
<tr>
<td><img src="images/img_1.jpg" alt="picture" width="182" height="127" class="floated" /></td>
</tr>
<tr>
<td> <p><%=objRS("p_nome")%><br /><span><%=objRS("p_desc")%></span></p></td>
</tr>
</table>
</div>
<a href="#" onclick="addToBasket(<%=c%>);return false;"><img src="images/acquista.gif" width="86" height="25" border="0" /></a>
<div class="clr"></div>
</div>
<!-- END DIV FOR A PRODUCT -->
<%
objRS.MoveNext
End if
Next
%>
Mentre poco dopo ho il carrello vero e proprio:
Codice:
<h2> Carrello</h2>
<div id="shopping_cart">
<table width="90%" border="0" id="shopping_cart_items">
<tr>
<th>Pr.</th>
<th>Cod</th>
<th>€</th>
<th></th>
</tr>
<%
if request("productId") <> "" then 'ho dovuto mettere un controllo altrimenti mi va in errore la select
Set objRS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT * FROM " &strDbTable& "prodotti WHERE p_status=1 AND idProdotto = "&request("productId")&" ORDER BY p_nome;"
objRS.Open strSQL, DFCon, 1, 1
If Not objRS.EOF Then
While Not objRS.EOF
%>
<tr id="shopping_cart_items_product<%=objRS("idProdotto")%>">
<th><%=objRS("p_nome")%></th>
<th><%=objRS("p_codice")%></th>
<th>€<%=objRS("p_prezzo")%></th>
<th></th>
</tr>
<%
objRS.MoveNext
Wend
End if
PuliziaRS(objRS)
end if
%>
</table>
<div id="shopping_cart_totalprice"></div>
</div>
La parte del js che gestisce il totale è questo:
Codice:
function showAjaxBasketContent(ajaxIndex)
{
// Getting a reference to the shopping cart items table
var itemBox = document.getElementById('shopping_cart_items');
var productItems = ajaxObjects[ajaxIndex].response.split('|||'); // Breaking response from Ajax into tokens
if(document.getElementById('shopping_cart_items_product' + productItems[0])){ // A product with this id is allready in the basket - just add number items
var row = document.getElementById('shopping_cart_items_product' + productItems[0]);
var items = row.cells[0].innerHTML /1;
items = items + 1;
row.cells[0].innerHTML = items;
}else{ // Product isn't allready in the basket - add a new row
var tr = itemBox.insertRow(-1);
tr.id = 'shopping_cart_items_product' + productItems[0]
var td = tr.insertCell(-1);
td.innerHTML = '1'; // Number of items
var td = tr.insertCell(-1);
td.innerHTML = productItems[1]; // Description
var td = tr.insertCell(-1);
td.style.textAlign = 'right';
td.innerHTML = productItems[2]; // Price
var td = tr.insertCell(-1);
var a = document.createElement('A');
td.appendChild(a);
a.href = '#';
a.onclick = function(){ removeProductFromBasket(productItems[0]); };
var img = document.createElement('IMG');
img.src = 'images/remove.gif';
a.appendChild(img);
//td.innerHTML = '<a href="#" onclick="removeProductFromBasket("' + productItems[0] + '");return false;"><img src="images/remove.gif"></a>';
}
updateTotalPrice();
ajaxObjects[ajaxIndex] = false;
}
function updateTotalPrice()
{
var itemBox = document.getElementById('shopping_cart_items');
// Calculating total price and showing it below the table with basket items
var totalPrice = 0;
if(document.getElementById('shopping_cart_totalprice')){
for(var no=1;no<itemBox.rows.length;no++){
totalPrice = totalPrice + (itemBox.rows[no].cells[0].innerHTML.replace(/[^0-9]/g) * itemBox.rows[no].cells[2].innerHTML);
}
document.getElementById('shopping_cart_totalprice').innerHTML = txt_totalPrice + totalPrice.toFixed(2);
}
}
Nel div shopping_cart_totalprice dovrebbe venir stampato il totale dei prodotti presenti nel carrello, invece mi stampa un Total: NaN
Ho il dubbio di aver capito male come gestire la parte del carrello..nello script originale lo gestisce in questo modo:
Codice:
<div id="rightColumn">
<!-- Shopping cart It's important that the id of this div is "shopping_cart" -->
<div id="shopping_cart">
<strong>Shopping cart</strong>
<table id="shopping_cart_items">
<tr>
<th>Items</th>
<th>Description</th>
<th>Price</th>
<th></th>
</tr>
<!-- Here, you can output existing basket items from your database
One row for each item. The id of the TR tag should be shopping_cart_items_product + productId,
example: shopping_cart_items_product1 for the id 1 -->
</table>
<div id="shopping_cart_totalprice"></div>
</div>
</div>
Cosa sto sbagliando secondo te?
Elisa | | |
| Asp | Active Server Pages | | |
| | |
| | |
| TR | TrustRank ( TR ) Assegnazione della fiducia. | | |
| | |