Foros del Web » Programando para Internet » Javascript »

Problemas con un cotizador

Estas en el tema de Problemas con un cotizador en el foro de Javascript en Foros del Web. Hola a Todos!! Ante todo quiero aclarar que no cuento con profundos conocimientos en java y por eso es que no puedo encontrarle la vuelta ...
  #1 (permalink)  
Antiguo 27/05/2006, 10:16
 
Fecha de Ingreso: febrero-2005
Mensajes: 86
Antigüedad: 19 años, 2 meses
Puntos: 1
Problemas con un cotizador

Hola a Todos!!
Ante todo quiero aclarar que no cuento con profundos conocimientos en java y por eso es que no puedo encontrarle la vuelta a un problema que tengo con un cotizador que he realizado a partir de un originalmente carrito de compras.
El asunto es que si bien funciona casi todo, hay dos cosas que no puedo saber donde tienen sus fallas: Una es que quiero que el detalle de los articulos que cotizaron aparezcan en algun campo en el formulario de manera que los pueda luego levantar desde la pagina ENVIAR.ASP para agregarlos a la BD y a la vez enviarlos por mail.
Y el otro problema es que si bien recibo por mail el o los articulos pedidos, tambien salen los que no se pidieron (repetidamente):
Producto:
Cantidad: en blanco desde luego...
Estas son las partes importantes de las tres primeras paginas. La de asp la coloco en otro post pq me la rechaza por que he hecho esto muy largo… disculpas….

art204.html (esta es la pagina del articulo en si mismo)

<html>
<head>
<title>Articulo 204</title>

</head>

<SCRIPT LANGUAGE="JavaScript">

function buyItem(newItem, newPrice, newQuantity) {
if (newQuantity <= 0) {
rc = alert('La cantidad ingresada es incorrecta');
return false;
}

if (confirm('¿Agregar '+newQuantity+' '+newItem+' a la cotización?')) {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
document.cookie="TheBasket="+document.cookie.subst ring(countbegin,
countend)+"["+newItem+","+newQuantity+"]";
}
return true;
}

function resetShoppingBasket() {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=.";
}
</SCRIPT>
....
<input name="agregar1" type="value" id="agregar1" value="1"
...
<input type="button" name="cbtadd" value="Solicitar"
onClick="buyItem('ART204','5.00', document.itemsform.agregar1.value)">
</table>
</div></td>
<td><div align="center"><a href="estado.htm"><img src="arts/images/ver.gif" width="60" height="20"
border="0"></a>
</div></td>
<td><div align="center"><a href="formulario.htm</a>
</div></td>
</form>

</body>
</html>


estado.html (muestra el estado del cotizador)

<html>
<head>
<title>Estado del Pedido</title>

</head>
<SCRIPT LANGUAGE="JavaScript">

function alterError(value) {
if (value<=0.99) {
newPounds = '0';
} else {
newPounds = parseInt(value);
}
newPence = parseInt((value+.0008 - newPounds)* 100);
if (eval(newPence) <= 9) newPence='0'+newPence;
newString = newPounds + '.' + newPence;
return (newString);
}
function showItems() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<form><table border="1" cellspacing="4" width="350" bgcolor="#708090" bordercolor="#FFFFFF"
class="td">');

document.writeln('<TR><TD width="80" align="center"><b>Artículo</b></TD><TD width="80" align="center"><b>Cantidad</b></TD><TD
width="80" align="center"><b>Modificar</b></TD></TR>');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
//itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
//var tax = itemtotal / 100 * (0 - 0);
//tax = Math.floor(tax * 100)/100
//totprice = totprice + itemtotal + tax;
itemlist=itemlist+1;
document.writeln('<tr><td>'+theitem+'</td><td align=center>'+thequantity+'</td><td align=center><input TYPE="button"
NAME="remove" VALUE="Eliminar" onclick="javascript:removeItem('+itemlist+')"></td></tr>');
} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}



//document.writeln('<tr><td colspan=3><b>Total</b></td><td
align=right>'+alterError(totprice)+'</td><td>&nbsp;</td></tr>');
document.writeln('</TABLE>');
}

function removeItem(itemno) {
newItemList = null;
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
theitem = fulllist.substring(itemstart, itemend);
itemlist=itemlist+1;
if (itemlist != itemno) {
newItemList = newItemList+'['+fulllist.substring(itemstart, itemend)+']';
}
}
}
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket="+newItemList;
top.location = "estado.htm";
}

function clearBasket() {
if (confirm('¿Confirma que desea reestablecer el pedido?')) {
index = document.cookie.indexOf("TheBasket");
document.cookie="TheBasket=.";
top.location = "estado.htm";
}
}
</SCRIPT>

<table width="485" border="0" align="center" cellpadding="0" cellspacing="0" class="body">
<tr>
<td width="50%"><font color="#000000">Estado de su Pedido</font></td>
<td width="50%" align="right"><font color="#000000"><a href="javascript:window.close()">Continuar Cotizando</a></font>| |<a href="formulario.asp"><font color="#000000">Cerrar Pedido</font></a></td>
</tr>

<SCRIPT LANGUAGE="JavaScript">
showItems();
</SCRIPT>
<br>
<tr>
<td width="100%" colspan="2">
<hr size="1" color="#FFFFFF">
</td>
</tr>
<tr>
<td width="50%"></td>
<td width="50%" align="right">[<font color="#000000"> <a href="javascript:clearBasket()">Reestablecer
Pedido</a> ]</font></td>
</tr>
</table>
</center>
</body>
</html>



formulario.html (el form para que introduzca todos los datos del cliente)

<html>
<head>
<title>Formulario de Cotizacion</title>

<SCRIPT LANGUAGE="JavaScript">


<!--
function Enviar(form) {
for (i = 0; i < form.elements.length; i++) {
if (form.elements[i].type == "text" && form.elements[i].value == "") {
alert("Por favor complete todos los campos del formulario"); form.elements[i].focus();
return false; }
}
form.submit();
}
// -->

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
//-->
</SCRIPT>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<SCRIPT LANGUAGE="JavaScript">

//function alterError(value) {
//if (value<=0.99) {
//newPounds = '0';
//} else {
//newPounds = parseInt(value);
//}
//newPence = parseInt((value+.0008 - newPounds)* 100);
//if (eval(newPence) <= 9) newPence='0'+newPence;
//newString = newPounds + '.' + newPence;
//return (newString);
//}

function showItems() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;

itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(thequantity));
temptotal = itemtotal * 100;
//var tax = itemtotal / 100 * (0 - 0);
//tax = Math.floor(tax * 100)/100
//totprice = totprice + itemtotal + tax;
itemlist=itemlist+1;
document.writeln('<INPUT TYPE="hidden" NAME="Producto'+itemlist+'" VALUE="'+theitem+'"
SIZE="40">');
document.writeln('<INPUT TYPE="hidden" NAME="Cantidad'+itemlist+'" VALUE="'+thequantity+'"
SIZE="40">')
//document.writeln('<INPUT TYPE="hidden" NAME="ProductoTotal'+itemlist+'"
VALUE="'+alterError(itemtotal)+'" SIZE="40">');
} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}

//document.writeln('<INPUT TYPE="hidden" NAME="Total" VALUE="'+alterError(totprice)+'" SIZE="40">');

}
function Total() {
document.writeln(alterError(totprice));
}

</SCRIPT>

<center>
<FORM method="post" action="enviar.asp" target="_top">
//AQUI SIGUE EL DESARROLLO DEL FORMULARIO


<SCRIPT LANGUAGE="JavaScript">
showItems();
</SCRIPT>

<td> <input name="enviar" type="submit" id="enviar" value="Enviar"> <input type="reset" value="Restablecer">
</td>
</form>
</body>
</html>
  #2 (permalink)  
Antiguo 27/05/2006, 10:17
 
Fecha de Ingreso: febrero-2005
Mensajes: 86
Antigüedad: 19 años, 2 meses
Puntos: 1
... Y esta es la que faltaba

enviar.asp (es la pagina que levanta toda la info del form, los pasa a la BD y envia el mail con el pedido).

<title>enviar</title><%

'Dim strEmail
Dim Producto, Cantidad, ProductoTotal, Total, Mail, index
'strEmail = Request.Form("email")
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "mail.midominio.com"
Mail.From = Request.Form("email")
Mail.FromName = Request.Form("nombre")
Mail.AddAddress "[email protected]"
Mail.Subject = "Solicitud de Cotización"
Mail.Body = "Solicitud de Cotización" & VbCrLf & VbCrLf

For index = 1 to Request.Form.Count

Producto = Request.Form("Producto" & index)
Cantidad = Request.Form("Cantidad" & index)
'ProductoTotal = Request.Form("ProductoTotal" & index)

Mail.Body = Mail.Body & "Producto" & index & ": " & Producto & VbCrLf
Mail.Body = Mail.Body & "Cantidad" & index & ": " & Cantidad & VbCrLf& VbCrLf & VbCrLf
'Mail.Body = Mail.Body & "ProductoTotal" & index & ": " & ProductoTotal & VbCrLf & VbCrLf

next

'Total = Request.Form("Total")
'Mail.Body = Mail.Body & "Total: " & Total & VbCrLf & VbCrLf
Mail.Body = Mail.Body & "Datos Personales:" & VbCrLf & VbCrLf
Mail.Body = Mail.Body & "Nombre-Apellido: " & Request.Form("nombre") & VbCrLf
Mail.Body = Mail.Body & "Empresa: " & Request.Form("empresa") & VbCrLf
Mail.Body = Mail.Body & "Ciudad: " & Request.Form("ciudad") & VbCrLf
Mail.Body = Mail.Body & "Provincia: " & Request.Form("provincia") & VbCrLf
Mail.Body = Mail.Body & "Pais: " & Request.Form("pais") & VbCrLf
Mail.Body = Mail.Body & "Telefono: " & Request.Form("telefono") & VbCrLf
Mail.Body = Mail.Body & "E-mail: " & Request.Form("email") & VbCrLf
Mail.Send

If Err <> 0 Then
Response.Write Err.Description
End If

Dim nombre, empresa, direccion, ciudad, provincia
Dim pais, telefono, email
Dim oConn, rs, SQL




'Recogemos el formulario
nombre=Request.Form("nombre")
empresa=Request.Form("empresa")
direccion=Request.Form("direccion")
ciudad=Request.Form("ciudad")
provincia=Request.Form("provincia")
pais=Request.Form("pais")
telefono=Request.Form("telefono")
email=Request.Form("email")
articulos=Request.Form("Producto" & index)
cantidad = Request.Form("Cantidad" & index)



' Creamos la conexion a la base de datos que omito


SQL="INSERT INTO pptos " & _
"(NomApell, Empresa, Direccion, Ciudad, Provincia, Telefono, Pais, Producto, Cantidad, Email, Fecha)"
SQL=SQL & " VALUES
('"&nombre&"','"&empresa&"','"&direccion&"','"&ciu dad&"','"&provincia&"','"&telefono&"','"&pais&"',' "&articulos&"','"&cantidad&"','"&email&"', #" & Month(Date) & "/" & Day(Date) & "/" & Year(Date) & "#);"
oConn.Execute(SQL)


oConn.Close
set oConn=nothing

If Err <> 0 Then
Response.Write Err.Description
End If


Response.Redirect "cotiz_ok.htm"
%>


Agradezco cualquier sugerencia pues debo terminarlo y no se como solucionarlo.

Edysierra
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:43.