26. marts 2002 - 22:12Der er
8 kommentarer og 1 løsning
Indkøbskurv
Hej jeg har et script til at insætte en købt varer i en indkøbskurv, men det virker ikke helt OK. Fejlen ligger nede ved de --- --- jeg har sat ind.
Sub AddProductToBag(avarProduct, BagItems) Set XMLDoc = BagItems.ownerDocument Set nodeFind = BagItems.selectNodes("product[@ProductNum=""" & nProductId & """]") If Not nodeFind.length > 0 Then Set product = XMLDoc.createElement("product") Set attr = XMLDoc.createAttribute("ProductNum") attr.Text = avarProduct(0,0) product.attributes.setNamedItem(attr) Set attr = XMLDoc.createAttribute("Name") attr.Text = Server.HtmlEncode(avarProduct(1,0)) product.attributes.setNamedItem(attr) Set attr = XMLDoc.createAttribute("price") attr.Text = avarProduct(2,0) product.attributes.setNamedItem(attr) product.text = "1" BagItems.appendChild(product) End If End Sub
Sub Out(strOut) Response.Write strOut End Sub
Sub PrintBag(BagItems) Out "<FORM METHOD=""POST"" ACTION=""" Out Request.ServerVariables("SCRIPT_NAME") & """>" Out "<TABLE><TR><TH>Units</TH><TH COLSPAN=2>" Out "Product</TH><TH>Unit Price</TH><TH>Price</TH>" Out "</TR>" & vbCrLf For Each item In BagItems.childNodes Out "<TR><TD><input type=""TEXT"" name=""Qty" ---------------------------------------------------- Out item.attributes.getNamedItem("ProductNum") Out """ VALUE=""" & item.text & """ SIZE=""3"">" ---------------------------------------------------- Out "<TD>" & item.attributes.getNamedItem("Name") Out "</TD><TD>" & item.attributes.getNamedItem("price") & "</TD>" nUnitPrice = item.attributes.getNamedItem("price") nSubTotal = item.text * nUnitPrice nTotal = nTotal + nSubTotal Out "<TD>" & FormatCurrency(nUnitPrice) & "</TD>" Out "<TD><B>" & FormatCurrency(nSubTotal) & "</B></TD>" Out "</TR>" & vbCRLF Next Out "<TR><TD COLSPAN=5><HR></TD></TR>" Out "<TR><TD COLSPAN=3></TD><TD><B>Total:</B></TD>" Out "<TD><B>" & FormatCurrency(nTotal) & "</B></TD></TR>" & vbCrLf Out "<TR><TD COLSPAN=5 ALIGN=""RIGHT"">" Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Shop for more""> " Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Recalculate""> " Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Check out"">" Out "</TD></TR></TABLE></FORM>" End Sub
DEn giver fejlen: ----- Response object error 'ASP 0185 : 80020003'
Missing Default Property
?
A default property was not found for the object --------- HVORFOR? Hvis der er nogen der har et andet script til en indkøbskurv er det meget velkommen. Jeg printer gerne hele kurven hvis det er nødvendigt..
I dette særtema ser vi på, hvordan cloud og AI bliver fundamentet for virksomhedernes digitale forretning, og hvordan de nye muligheder for automatisering og forretningsværdi kan udnyttes uden at miste overblik, sikkerhed og menneskelig kontrol.
Her kommer hele bag.asp. I browseren står der: /bag.asp?id=10010
<% Response.Buffer = True %> <html> <head> <title>Implementing the Shopping Bag</title> </head> <body bgcolor="#ffffff"> <% Set BagItems = LoadXMLBag()
If Request.ServerVariables("CONTENT_LENGTH") > 0 Then Select Case Trim(Request.Form("DO")) Case "Shop for more" Response.Redirect "products.asp" Response.End Case "Recalculate" RecalcBag BagItems Case "Check out" ' recalculate and then redirect to checkout End Select Else ' products are added using the query string nProductId = Trim(Request.QueryString("id")) AddtlProduct nProductId, BagItems End If
Session("BagItems") = BagItems.XML
If BagItems.hasChildNodes Then PrintBag BagItems Else Response.Write "hej" End If %> <p> " </body> </html>
<SCRIPT LANGUAGE=VBSCRIPT RUNAT=SERVER> Function LoadXMLBag() Set XMLDoc = Server.CreateObject("Microsoft.XMLDOM") If Not IsEmpty(Session("BagItems")) Then XMLDoc.loadXML CStr(Session("BagItems")) Set BagItems = XMLDoc.documentElement Else Set BagItems = XMLDoc.createElement("BagItems") Set XMLDoc.documentElement = BagItems End If Set LoadXMLBag = BagItems End Function
Sub AddtlProduct(nProductId, BagItems) bValid = True
If "" = nProductId Or Not IsNumeric(nProductId) Then bValid = False Else
Set objConn = Server.CreateObject("ADODB.Connection") Set Rs = Server.CreateObject("ADODB.Recordset")
Set objRS = Server.CreateObject("ADODB.Recordset") Set objRS.ActiveConnection = objConn objRS.Open "SELECT * FROM items WHERE ProductNum=" & nProductId If objRS.EOF And objRS.BOF Then bValid = False Else avarProduct = objRS.GetRows() End If objConn.Close Set objRS = Nothing Set objConn = Nothing End If
' if the product was ok, add it to the bag If bValid Then AddProductToBag avarProduct, BagItems End If End Sub
Sub AddProductToBag(avarProduct, BagItems) Set XMLDoc = BagItems.ownerDocument Set nodeFind = BagItems.selectNodes("product[@ProductNum=""" & nProductId & """]") If Not nodeFind.length > 0 Then Set product = XMLDoc.createElement("product") Set attr = XMLDoc.createAttribute("ProductNum") attr.Text = avarProduct(0,0) product.attributes.setNamedItem(attr) Set attr = XMLDoc.createAttribute("Name") attr.Text = Server.HtmlEncode(avarProduct(1,0)) product.attributes.setNamedItem(attr) 'Set attr = XMLDoc.createAttribute("quantityperunit") 'attr.Text = Server.HtmlEncode(avarProduct(2,0)) 'product.attributes.setNamedItem(attr) Set attr = XMLDoc.createAttribute("price") attr.Text = avarProduct(2,0) product.attributes.setNamedItem(attr) product.text = "1" BagItems.appendChild(product) End If End Sub
Sub Out(strOut) Response.Write strOut End Sub
Sub PrintBag(BagItems) Out "<FORM METHOD=""POST"" ACTION=""" Out Request.ServerVariables("SCRIPT_NAME") & """>" Out "<TABLE><TR><TH>Units</TH><TH COLSPAN=2>" Out "Product</TH><TH>Unit Price</TH><TH>Price</TH>" Out "</TR>" & vbCrLf For Each item In BagItems.childNodes Out "<TR><TD><input type=""TEXT"" name=""Qty" Out item.attributes.getNamedItem("ProductNum") Out """ VALUE=""" & item.text & """ SIZE=""3"">" Out "<TD>" & item.attributes.getNamedItem("Name") Out "</TD><TD>" & item.attributes.getNamedItem("price") & "</TD>" nUnitPrice = item.attributes.getNamedItem("price") nSubTotal = item.text * nUnitPrice nTotal = nTotal + nSubTotal Out "<TD>" & FormatCurrency(nUnitPrice) & "</TD>" Out "<TD><B>" & FormatCurrency(nSubTotal) & "</B></TD>" Out "</TR>" & vbCRLF Next Out "<TR><TD COLSPAN=5><HR></TD></TR>" Out "<TR><TD COLSPAN=3></TD><TD><B>Total:</B></TD>" Out "<TD><B>" & FormatCurrency(nTotal) & "</B></TD></TR>" & vbCrLf Out "<TR><TD COLSPAN=5 ALIGN=""RIGHT"">" Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Shop for more""> " Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Recalculate""> " Out "<INPUT TYPE=SUBMIT NAME=""DO"" VALUE=""Check out"">" Out "</TD></TR></TABLE></FORM>" End Sub
Sub RecalcBag(BagItems) For Each item in BagItems.childNodes nQty = Trim(Request.Form("Qty" & item.attributes.getNamedItem("ProductNum"))) If "" <> nQty And IsNumeric(nQty) Then If nQty < 1 Then BagItems.removeChild item Else item.text = nQty End If End If Next End Sub </SCRIPT> -------------- Fejlen er stadig den samme som tidligere nævnt. What dælen do I do?
Dine forslag giver følgende: -------------------- Out item.attributes.getNamedItem("ProductNum") Out """ VALUE=""" & item.attributes.getNamedItem("name") & """ SIZE=""3"">" ------------------- Giver sammefejl som før
------------------------- Out item.getNamedItem("ProductNum") Out """ VALUE=""" & item.getNamedItem("name") & """ SIZE=""3"">" -------------------------- Giver: Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method: 'item.getNamedItem'
/shop/bag.asp, line 124
og sidst giver: ---------------------- Microsoft VBScript runtime error '800a01b6'
Object doesn't support this property or method
/shop/bag.asp, line 130
Men du har ret i at det er disse linier den fucker ud
Jeg droppede ovenstående kode, og lavede noget styret af sessions og arrays...
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.