Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

thaiss

Function de add no carrinho.

Recommended Posts

A function a seguir adiciona produtos em um carrinho de compras e valida o campo "quantidade":

 

<script>function addtocart(formele,prodid){dml=document.f1;dml2=document.f2;product=dml.elements[formele];total=dml2.elements[0]; if(isNaN(product.value) || product.value=="")     {       alert("Por favor, entre com a quantidade");      product.value="";      product.focus();      //return false;     } else{            total.value=prodid +","+Math.ceil(product.value);      dml2.submit();      }//return true;}  function removecart(removeprod){    location.href="submitshop.asp?choice=remove&removeprod="+removeprod      }</script>

Há um outro campo de formulario onde o cliente escolherá o tamanho do uniforme, o erro q está acontecendo é o seguinte:

Ele valida corretamente a primeira linha e a segunda ele valida mesmo com o campo preenchido.

 

Vejam o funcionamento em www.digiexpress.com.br/pedido2/tha/shop/catalogo2.asp

 

 

Algum ser solidário poderia me ajudar ?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Se entrar na pagina www.digiexpress.com.br/pedido2/tha/shop/catalogo2.asp irá entender melhor!você verá la varios itens a serem add no pedido.O primeiro item inclui normalmente, mas o segundo não.O terceiro item inclui normalmente, o quarto não.......

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deus do céu,...

o jeito que você fez é muito treta de gerenciar, pelo indice do campo no formulário... tenta sempre usar o ID e recuperar o elemento pelo document.getElementById....

 

Por exemplo, você ta usando ASP, certo???

 

Gera pra todos os campos de quantidade uma Id unica... tipo assim:

 

<input type="text" name="product" id="campoQtde<% rs("productID") %>" size="4" style="font-family: Verdana; font-size: 10; text-align: center">

Dai na hora de criar o link pra adicionar, passa o CAMPO e o ID do produto:

 

<a href="javascript:addtocart('campoQtde<% rs("productID") %>',<% rs("productID") %>);">

No hidden de total tb coloca um ID

 

<input type="hidden" name="total" id="total" size="20">

 

Porque dai na função, você recupera ele pelo document.getElementById

 

function addtocart(formele,prodid){product=document.getElementById(formele);total=document.getElementById("total"); if(isNaN(product.value) || product.value=="")     {       alert("Por favor, entre com a quantidade");      product.value="";      product.focus();      //return false;     } else{            total.value=prodid +","+Math.ceil(product.value);      dml2.submit();      }//return true;}

Do jeito q você ta fazendo você vai ficar doida....

Tenta assim, sei lá, só uma dica, qualquer coisa posta ae!!

:D

Compartilhar este post


Link para o post
Compartilhar em outros sites

É MUUIIIIIIIIIITA COISA ..VOU TENTAR RESUMIR .. =\<% Response.CacheControl="no-cache" Response.AddHeader "Pragma","no-cache" Response.Expires=0%> <!-- #include file="../include/top.asp" --><%sql="select * from Items"set rs=conn.execute(sql) count=0%><html><head><meta http-equiv="Content-Language" content="en-us"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><meta name="GENERATOR" content="Microsoft FrontPage 5.0"><meta name="ProgId" content="FrontPage.Editor.Document"><title>Lutha Uniformes</title><script>function addtocart(formele,prodid){product=document.getElementById(formele);total=document.getElementById("total");if(isNaN(product.value) || product.value=="") { alert("Por favor, entre com a quantidade"); product.value=""; product.focus(); //return false; }else{ total.value=prodid +","+Math.ceil(product.value); dml2.submit(); }//return true;} function removecart(removeprod){ location.href="submitshop.asp?choice=remove&removeprod="+removeprod }</script><style type="text/css"><!--body { background-color: #EEE8FF;}--></style></head><body style="background-color: #FFFFFF"><div align="center" width="100%" style="width: 655; height: 41"><center><form method="POST" name="f1"><% while not rs.eof %><table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-left-width:0; border-top-width:0; border-bottom-width:0" bordercolor="#111111" width="100%"> <tr> <td width="26%" style="border-style: none; border-width: medium"> <font face="Verdana" style="font-size: 8pt"><%=rs("desc")%> </td> <td width="10%" style="border-style: none; border-width: medium"> <font face="Verdana" style="font-size: 8pt"><p align="center"><%=rs("mod")%> </td> <td width="18%" style="border-style: none; border-width: medium"> <font face="Verdana" style="font-size: 8pt"><p align="center"><%=rs("cor")%> </td> <td width="8%" style="border-style: none; border-width: medium"> <font face="Verdana" style="font-size: 8pt"><p align="center"><%=rs("ref")%> </td> <td width="10%" style="border-style: none; border-width: medium"> <p align="center"><span lang="pt-br"><font face="Verdana" style="font-size: 8pt">  </font></span><font face="Verdana" style="font-size: 8pt">R$ <%=rs("valor")%></font></td> <td width="10%" style="border-style: none; border-width: medium"> <p align="center"> <font color="#800080" face="Verdana" style="font-size: 8pt"><input type="text" name="product" id="campoQtde<% rs("ProductID") %>" size="4" style="font-family: Verdana; font-size: 10; text-align: center"></font></td> <td width="9%" style="border-left-style: none; border-left-width: medium; border-top-style: none; border-top-width: medium; border-bottom-style: none; border-bottom-width: medium"> <p align="center"> <select size="1" name="tamanho" style="font-family: Verdana; font-size: 10"><option>36</option><option>38</option><option>40</option><option>42</option><option>44</option><option>46</option><option>48</option><option>50</option><option>52</option><option>54</option><option>56</option></select></td> <td width="9%" style="border-left-style: solid; border-left-width: 1; border-top-color: #111111; border-top-width: 1; border-bottom-color: #111111; border-bottom-width: 1; border-right-style:solid; border-right-width:1" bgcolor="#F2F2F2"> <p align="center"><font face="Verdana"><a href="java script:addtocart('campoQtde<% rs("ProductID") %>',<% rs("ProductID") %>);"><span style="font-size: 8pt; font-weight:700"><font color="#000000">Incluir</font></span></a></td> </tr></table><br> <% count=count+1 rs.movenext wend %> </form><form method="POST" action="submitshop.asp?choice=shop" name="f2"> <font size="1"> <input type="hidden" name="total" id="total" size="20"> </font> </form> </center></div> </td> </tr></table></html><!-- #include file="../include/bottom.asp" -->

Compartilhar este post


Link para o post
Compartilhar em outros sites

O código do produto chama ProductID mesmo???

 

Então só tava faltando o "=" no codigo q eu te passei

 

<a href="javascript:addtocart('campoQtde<%= rs("ProductID") %>',<%= rs("ProductID") %>);">

Senão da pau mesmo!!

qualquer coisa grita!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ok .. mas continua o mesmo erro na mesma linha ..<a href="java script:addtocart('campoQtde<% rs("productID") %>',<% rs("productID") %>);">..é ProductID mesmo

Compartilhar este post


Link para o post
Compartilhar em outros sites

você colocou o igual????

 

 

<%= rs("productID") %>

 

<a href="javascript:addtocart('campoQtde<%= rs("productID") %>',<%= rs("productID") %>);">

Compartilhar este post


Link para o post
Compartilhar em outros sites

Aiii Senhorrrrrrrrrrrrrrrrrrrrrrrrrrrrrro erro agora é em:<input type="text" name="product" id="campoQtde<% rs("productID") %>" size="4" style="font-family: Verdana; font-size: 10; text-align: center">

Compartilhar este post


Link para o post
Compartilhar em outros sites

Falta o "=" também!!!!!

Senão não funciona!!! ahh!!

 

 

<%= rs("productID") %>

 

 

<input type="text" name="product" id="campoQtde<%= rs("productID") %>" size="4" style="font-family: Verdana; font-size: 10; text-align: center">

Compartilhar este post


Link para o post
Compartilhar em outros sites

Nossa ... Simplesmente, muito orbrigado.Quando eu nasci Deus falou: "Esse ser nunca vai saber mexer com javascript e asp direito" .. RsssValeu mesmo hein ... agora falta terminar a parte em asp .. =\ hauhuahua ... mas ja adiantei bastante coisa .. Bjaum

Compartilhar este post


Link para o post
Compartilhar em outros sites

hahahahahase liga, pára de ser bobaé só praticar q vai aprendendo, eu também apanho pra caramba mas tenho aprendido muita coisa aqui nesse fórum, então não custa ajudar as vezes...Qualquer coisa posta ai!!Se quiser tenho várias apostilas de javascript em casa, posso te passar por email..bjos

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.