Ciao, sto cercando di creare un sistema per aggiungere prodotti in un carrello i un e-commerce che funziona così:
- clicco sul pulsante "add" e mi si apre la finestrella con lightbox in cui si scelngono quantità e eventuali altri dati
- al click su "OK" viene richiamata la pagina asp che aggiunge i dati nel db
(l'idea l'ho scopiazzata dalla gestione della wishlist di istockphoto)
Il mio problema è il seguente: quando mi compaiono le finiestrelle lightbox, al loro interno c'è sempre la stessa form con i dati relativi all'ultimo prodotto visualizzato nella lista... quindi funziona tutto correttamente se non che mi va a caricare nel carrello sempre lo stesso prodotto
Non riesco a trovare dove sta il problema... posto qui sotto il codice usato:
all'interno del ciclo per la visualizzazione dei prodotti (quindi per ogni prodotto):
Codice PHP:
<div class="paddingDiv" id="imageTableDisplayItem_<%=prodottiRS("ar_codart")%>">
<div onmouseover="this.style.cursor = 'pointer';" id="Div<%=prodottiRS("ar_codart")%>">
<script type="text/javascript">ObjDiv<%=prodottiRS("ar_codart")%> = new AddToLightbox("<%=prodottiRS("ar_codart")%>__", "Div<%=prodottiRS("ar_codart")%>" , "<%=prodottiRS("ar_codart")%>", "lightboxPopupBox", "LightboxForm", "lightboxPopupBoxReset", "true", "img/<%=session("folder")%>/carrello/lightbox_add.gif", "", "", "", "Aggiungi al carrello", "?riga=<%=i%>&moltiplicatore=<%=moltiplicatore%>&tb_codgmer=<%=tb_codgmer%>&tb_codsgme=<%=tb_codsgme%>&<%=variabili%>");</script>
</div>
</div>
Form base:
Codice PHP:
<form id="LightboxForm" action='carrello.asp' name="LightboxForm" method="POST" >
<input type="hidden" name="FormName" value="LightboxForm">
<input type="hidden" name="FileID" value="" id="FileID" />
<input type="hidden" name="SearchCacheID" value="" id="SearchCacheID" />
<input type="hidden" name="LightboxID" value="" id="LightboxID" />
<div id="lightboxPopupBox" class="popupBox">
<div class="right">
[img]img/<%=session([/img]/carrello/loading_small.gif" width="14" height="15" id="AddToLightboxLoading" style="display: none; margin-right: 3px;" alt="Loading..."/>
[img]img/<%=session([/img]/carrello/help_box.gif" width="14" height="15" id="AddToLightboxHelpButton1" style="cursor: pointer;" title="Show Help"
onClick="lightboxPopupBoxShowHelp('lightboxPopupBox');"/>
[img]img/<%=session([/img]/carrello/help_box2.gif" width="14" height="15" id="AddToLightboxHelpButton2" style="display: none; cursor: pointer;" title="Hide Help"
onClick="lightboxPopupBoxHideHelp('lightboxPopupBox');"/>
[img]img/<%=session([/img]/carrello/close_box.gif" width="14" height="15" style="cursor: pointer;" title="Close"
onClick="lightboxPopupBoxClose();"/>
</div>
<div style="display: none" id="AddToLightboxResponseMessages" class="popupBoxResponseMessages"></div>
<div id="AddToLightboxContentAdd">
<div style="margin-left: 15px;">
[b]Aggiungi al carrello:[/b]
<input type="text" id="qta" name="qta" value="" maxlength="3" size="3"/>
<input type="text" name="variabiliXXX" value="XX" />
</div>
<div class="right">
<input type="image" id="AddButton" name="AddButton" alt="AddButton" title="AddButton" src="img/<%=session("folder")%>/carrello/aggiungi.gif" height="18" />
</div>
</div>
<div id="AddToLightboxContentHelp" style="display: none; cursor: pointer; line-height: 16px;" onclick="lightboxPopupBoxHideHelp('lightboxPopupBox')" title="Hide Help">
Per aggiungere l'articolo al carrello, indica la quantità desiderata e clicca sul pulsante OK.
</div>
</div>
</div>
</form>
Javascript per la gestione lightbox:
Codice PHP:
var AddToLightbox = Class.create();
AddToLightbox.prototype = {
initialize: function(id, parentNodeID, fileID, popupBoxID, formName, jsCallback, isModal, imgSrc, label,seachCacheID, copyLightboxID, imgTitle, variabili) {
this.id = id;
this.parentNodeID = parentNodeID;
this.labelID = "addToLightBoxLabel_" + id;
this.buttonID = "addToLightBoxButton_" + id;
this.fileID = fileID;
this.popupBoxID = popupBoxID;
this.formName = formName;
this.jsCallback = jsCallback;
this.isModal = isModal;
this.imgSrc = imgSrc;
this.searchCacheID = seachCacheID;
this.copyLightboxID = copyLightboxID;
this.imgTitle = imgTitle;
this.label = label;
this.variabili = variabili;
this.variabiliXXX = variabili;
this.buildLink();
},
buttonClick: function(e) {
showPopupBox($(this.popupBoxID), e, this.jsCallback, this.isModal);
$(this.formName).FileID.value = this.fileID;
$(this.formName).SearchCacheID.value = this.searchCacheID;
$(this.formName).LightboxID.value = this.copyLightboxID;
$(this.formName).action = 'http://www.yahoo.it';
},
buildLink: function() {
var img = document.createElement("img");
img.setAttribute("id", this.buttonID);
img.setAttribute("src", this.imgSrc);
img.setAttribute("alt", "Add To Lightbox");
img.setAttribute("title", this.imgTitle);
img.setAttribute("className", 'lightboxAdd');
img.setAttribute("class", 'lightboxAdd');
img.onclick = this.buttonClick.bind(this);
$(this.parentNodeID).appendChild(img);
var span = document.createElement("span");
span.setAttribute("id", this.labelID);
span.innerHTML = this.label;
span.onclick = this.buttonClick.bind(this);
$(this.parentNodeID).appendChild(img);
$(this.formName).action = "carrello_ajax.asp" + this.variabili;
}
}
(il codice potrebbe essere un po' sporcato dai vari test che sto facendo...)
Grazie &