Foros del Web » Programando para Internet » Javascript »

multiplicar arreglo con javascript

Estas en el tema de multiplicar arreglo con javascript en el foro de Javascript en Foros del Web. hola a todos, veran tengo un problema con este codigo nececito que cuando este sobre el text de total hilo me multiplique lo del text ...
  #1 (permalink)  
Antiguo 25/11/2011, 17:19
 
Fecha de Ingreso: noviembre-2011
Ubicación: IBAGUE
Mensajes: 2
Antigüedad: 12 años, 5 meses
Puntos: 0
Pregunta multiplicar arreglo con javascript

hola a todos, veran tengo un problema con este codigo
nececito que cuando este sobre el text de total hilo me multiplique lo del text cantidad y el text valor...

tengo una parte que hace que aparezcan los textbox, en la primera fila me sirve pero agrego otra y de hay en adelante no me sirve

plisssssssssss ayuda!!!!

adjunto codigo


<?php
include "conexion.php";
include "seguridad.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="es" xml:lang="es">
<head>
<title>Agregar campos</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Inventario</title>
<link href="css/jquery-ui-1.8.12.custom.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.12.custom.min.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript">
$(function(){
$( "input:button, input:submit, a", ".demo" ).button();
$( "a", ".demo" ).click(function() { return false; });
$( "#datepicker" ).datepicker();
});

function cambiavalor(cantidad,valor,total){
valor3=parseFloat(document.getElementById('cantida d').value);
valor4=parseFloat(document.getElementById('valor') .value);
document.getElementById('total').value= valor3 * valor4 ;



}


</script>
</head>
<?php

if (isset($_POST['guardar']))
{
$dato1 = $_POST['titulo'];
foreach ($dato1 AS $titulo){
$dato2 = $_POST['cantidad'];
$dato3 = $_POST['valor'];
$dato4 = $_POST['total'];
$dato5 = $_POST['proveedortyt'];
foreach ($dato2 AS $cantidad){}
foreach ($dato3 AS $valor){}
foreach ($dato4 AS $total){}
foreach ($dato5 AS $proveedortyt){}

$SQL = "INSERT INTO hilaza (fecha,factura,remision,proveedor,titulo,cantidad) VALUES('$fecha','$factura','$remision','$proveedor ','".$titulo."','".$cantidad."','".$valor."','".$t otal."','".$proveedortyt."')";
mysql_query($SQL) or die (mysql_error());
}


}

?>
<body class="demo">
<form id="gencampo" name="gencampo" action="<?php echo $_SERVER['PHP_SELF']?>" method="post" class="demo">

<table>
<tr><td>
<?php $rs = mysql_query("SELECT MAX(id) AS id FROM hilaza");
if ($row = mysql_fetch_row($rs)) {
$id = trim($row[0]);}?>
<input type='button' value="<?php echo $id+1 ;?>" ></td>


<td>Fecha de entrada:</td>
<td><input type="text" id="datepicker" name="fecha"/></td>
<td>Factura:</td>
<td><input type="text" name="factura"/></td>
<td>Remisi&oacute;n:</td>
<td><input type="text" name="remision"/></td>
<td colspan="2"><?php
echo 'Proveedor: ';
$sSQL="Select * From proveedores Order By nombre";
$result=mysql_query($sSQL);
echo '<select name="proveedor">';
while ($row=mysql_fetch_array($result))
{echo '<option>'.$row["nombre"];}
mysql_free_result($result)
?></select>
</td>
</tr>
</table>
<table>
<tr>
<td width="108" align="center">Titulo hilo</td>
<td width="153" align="center">Cantidad hilo</td>
<td width="153" align="center">Valor hilo</td>
<td width="153" align="center">Total hilo</td>
<td width="100" align="center">Provedor Servicio<br/> T y T</td>
</tr>
</table>
</table>
<table id="tabla">
<tr>
<input type="hidden" name="var_cont">
</tr>
<tr>
<td valign="top"><input type="button" name="b1" value="Agregar" onClick="camponuevo()">
<input type="button" name="b2" value="Quitar" onClick="borrar()" >
<input type="submit" name="guardar" id="b3" value="Guardar"></td>
</tr>
</table>
</form>
<script language='JavaScript'>
var cont=0;
function camponuevo(){ //Esta la funcion que agrega los campos :
cont++;
var indiceFila=1;
campof = document.getElementById('tabla').insertRow(-1);
campof.id=indiceFila;
campo=campof.insertCell(-1);
campo.innerHTML='<tr><td><?php $sSQL="Select * From titulo Order By titulo"; $result=mysql_query($sSQL); echo '<select name="titulo[]">'; while($row=mysql_fetch_array($result)){echo '<option>'.$row["titulo"];} mysql_free_result($result)?><input type="text" name="cantidad" id="cantidad"/><input type="text" name="valor" id="valor" /><input type="text" name="total" id="total" onfocus="cambiavalor()" readonly="readonly" /><?php $sSQL="Select * From proveedores Order By nombre"; $result=mysql_query($sSQL); echo '<select name="proveedortyt">'; while ($row=mysql_fetch_array($result)) {echo '<option>'.$row["nombre"];} mysql_free_result($result) ?></td></tr>';
indiceFila++;
}
function borrar() {
var table = document.getElementById('tabla');
if(table.rows.length > 3)
{
table.deleteRow(table.rows.length -1);
cont--;
}
}
</script>
</body>
</html>
  #2 (permalink)  
Antiguo 28/06/2012, 09:49
Avatar de Ilidam  
Fecha de Ingreso: julio-2009
Ubicación: Veracruz
Mensajes: 108
Antigüedad: 14 años, 9 meses
Puntos: 0
Respuesta: multiplicar arreglo con javascript

Hola que tal oye el escript k tienes para genarar filas te funciona bien?? y la consulta k haces a la base = te muestra los datos solicitados???
  #3 (permalink)  
Antiguo 28/06/2012, 14:50
 
Fecha de Ingreso: noviembre-2011
Ubicación: IBAGUE
Mensajes: 2
Antigüedad: 12 años, 5 meses
Puntos: 0
Respuesta: multiplicar arreglo con javascript

ya solucione todo el inconveniente, es mas ya termine el proyecto que estaba realizando :D

Etiquetas: arrays, javascript+php
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 03:57.