Foros del Web » Programando para Internet » Javascript »

Incluir otra variable

Estas en el tema de Incluir otra variable en el foro de Javascript en Foros del Web. Hola amigos, tengo el siguiente script, pero lo que necesito es almacenar en una variable el campo precios de mi tabla precios, logicamente es una ...
  #1 (permalink)  
Antiguo 14/09/2006, 09:13
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 17 años, 10 meses
Puntos: 1
Información Incluir otra variable

Hola amigos, tengo el siguiente script, pero lo que necesito es almacenar en una variable el campo precios de mi tabla precios, logicamente es una instruccion sql y solamente tendra un precio ya que la estoy intentando delimitar con un where, pero necesito compararlo con esa variable, espero me entiendan.

Código HTML:
<script language = "JavaScript">
<%'CONSULTA PARA OBTENER LOS DATOS
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("./Ventas2.mdb"))

productos_Sql = "Select * from precios ORDER BY tipo_producto"
set rs = CreateObject("ADODB.Recordset")
rs.Open productos_Sql, Conn
x=0
%>

// FUNCION DE COMBO BOX COMBINADO
function sublist(inform, selecteditem)
{ inform.subcatagory.length = 0

<%
count= 0
y=0
do while not rs.eof
%>
x = <%= trim(y) %>;

subcat = new Array();
[COLOR="Red"][B]subcatagorys = "<%=(rs("tipo_producto"))%>";
subcatagoryof = "<%=(rs("id"))%>";
subcatagoryid = "<%=(rs("tipo_producto"))%>";
subcat[x,0] = subcatagorys;
subcat[x,1] = subcatagoryof;
subcat[x,2] = subcatagoryid;[/B][/COLOR]

[COLOR="RoyalBlue"][B]<% pre_sql="Select precio From Precios Where tipo_producto= 'subcatagorys' "
set rs2 = CreateObject("ADODB.Recordset")
rs2.Open pre_Sql, Conn %>[/B][/COLOR]

FRMCLIENTE.T1.value= document.FRMCLIENTE.subcatagory.value;
FRMCLIENTE.precio.value = [COLOR="royalblue"][B]"<%=pre_sql%>";[/B][/COLOR]

if (subcat[x,1] == selecteditem) {
	var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,2]);
	inform.subcatagory.options[inform.subcatagory.length]=option<%= trim(count)%>;}
		
<%
count = count + 1
y = y + 1
rs.movenext
loop
rs.close
%>
}
</script> 
La parte q esta en rojo pertecene a la asignacion de variables desde mi base de datos, pero como incluyo otra con el precio que deseo q tenga?

El codigo azul es mi sentencia sql, q he pensado q me puede ser util para traer solo 1 precio pero en la asignacion de abajo falla, diganme q estoy haciendo mal, o q necesito hacer.

Gracias por todo, espero sugerencias.
  #2 (permalink)  
Antiguo 15/09/2006, 08:15
 
Fecha de Ingreso: junio-2006
Mensajes: 104
Antigüedad: 17 años, 10 meses
Puntos: 1
Despues de muchos golpazos de cabeza en el esctitorio, por fin le pude dar solucion. aqui se las mando.

Venta.asp
<html> <head>
<link rel="STYLESHEET" type="text/css" href="css/letras.css">
<meta http-equiv="Content-Language" content="es">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<title>Ventas</title>
<!--#include file="Funciones.asp"-->
</head>

<body >
<%Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("./Ventas2.mdb"))%>

<h1 align="center">Venta de productos</h1>
<form name="FRMCLIENTE" method=POST target=_self action="">
<p align="center">Seleccione el producto a comprar:

<select size="1" id="Productos" name="Productos" onChange = "javascript:sublist(this.form, Productos.value);">
<option selected>Selecciona un Producto</option>
<%productos_Sql = "Select distinct id, productos from productos ORDER BY Productos"
rs.Open productos_Sql, Conn
do while not rs.eof
%>
<option value="<%=rs("id")%>"><%=rs("productos")%></option>
<%rs.movenext
loop%>
</select>

</p>

<table border="1" width="80%" height="58" align="center">
<tr>
<td width="25%" height="1" align="center">
<p align="center"><b>Productos</b></p>
</td><td width="13%" height="1" align="center">
<p align="center"><b>Cantidad</b></p>
</td>
<td width="12%" height="1" align="center">
<b>Precio</b>
</td><td width="21%" height="1" align="center">
<p align="center"><b>Sub-Total</b></p>
</td>
<td width="29%" height="1" align="center">
<p align="center"><b>Comprar</b></p>
</td>
</tr>
<tr>
<td width="25%" height="1">
<SELECT id="subcatagory" name="subcatagory" size="1" onChange = "javascript:sublist(precio.value = this.value);">
<Option selected value="none"></option>
</SELECT>

</td>
<td width="12%" height="1" align="center">
<p align="center"><input type="text" name="Cantidad" size="10" onkeypress="return numero(event,this.value)"></p>
</td>
<td width="21%" height="1">

<input type="text" name="precio" size="12" disabled>

</td>
<td width="29%" height="1">
<p align="center">
<input type="text" name="T1" size="23" disabled>

</td>
</tr></table>
<%set rs=nothing
conn.close
set conn=nothing%>

</Form></body>

************************************************** ******************

Funciones.asp

<script language = "JavaScript">
<%'CONSULTA PARA OBTENER LOS DATOS
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("./Ventas2.mdb"))

productos_Sql = "Select * from precios ORDER BY tipo_producto"
set rs = CreateObject("ADODB.Recordset")
rs.Open productos_Sql, Conn
x=0
%>

// FUNCION DE COMBO BOX COMBINADO
function sublist(inform, selecteditem)
{ inform.subcatagory.length = 0

<%
count= 0
y=0
do while not rs.eof
%>
x = <%= trim(y) %>;

subcat = new Array();
subcatagorys = "<%=(rs("tipo_producto")) %>";
subcatagoryof = "<%=(rs("id"))%>";
subcatagoryid = "<%=(rs("precios"))%>";
subcat[x,0] = subcatagorys;
subcat[x,1] = subcatagoryof;
subcat[x,2] = subcatagoryid;

FRMCLIENTE.precio.value= document.FRMCLIENTE.subcatagory.value;

if (subcat[x,1] == selecteditem) {
var option<%= trim(count) %> = new Option(subcat[x,0], subcat[x,2]);
inform.subcatagory.options[inform.subcatagory.length]=option<%= trim(count)%>;}

<%
count = count + 1
y = y + 1
rs.movenext
loop
rs.close
%>
}

function numero(e,txt){
tecla = (document.all) ? e.keyCode : e.which;
if (tecla==8) return true;
if (tecla==46 && txt.indexOf('.') != -1) return false;
patron = /[\d\.]/;
te = String.fromCharCode(tecla);
return patron.test(te); }
</script>

************************************************** **********
Espero les sirva para un futuro. La parte coloreada es donde mando el precio de mi BD a un text. Gracias y nos vemos pronto.
Si hay dudas pregunten y si alguien tiene ideas mejores, q las pongan, asi nos ayudamos a mejorar nuestras Web's.
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 19:14.