PHP - programacion php y javascript

 
Vista:

programacion php y javascript

Publicado por daniel (2 intervenciones) el 11/06/2010 02:46:08
hola que tal, mi problema es que necesito sumar las cantidades y no se como, alguien me podria ayudar, les pongo el

////en este paso va creando nuevos campos de texto las cuales voy insertando para posteriormente mandarlas al doc dos.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
<script>
var contLin = 1, tr, td, tabla;
function agregar() {
alert (contLin);
document.getElementById("OcultoContLin").value = contLin;
//var
tabla = document.getElementById('TablaMed');
tr = tabla.insertRow(tabla.rows.length);
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' size='20' name='t" + contLin + "1' id='t" + contLin + "1' value='t" + contLin + "1'>";
//alert (document.getElementById(td.innerHTML).id);
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' size='3' name='t" + contLin + "1' id='t" + contLin + "2' value='t" + contLin + "2'>";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<input type='text' size='10' name='t" + contLin + "1' id='t" + contLin + "3' value='t" + contLin + "3'>";
td = tr.insertCell(tr.cells.length);
td.innerHTML = "<textarea cols='15' rows='1' id='t" + contLin + "4'>t" + contLin + "4";
contLin++;

}

function eliminarultima() {
ultima = document.all.TablaMed.rows.length - 1;

if(ultima > 0){
document.all.TablaMed.deleteRow(ultima);
contLin--;
document.getElementById("OcultoContLin").value = contLin-1;
}
}

function datosTextos() {
var textos = '';
for (var i=1;i<document.getElementById('TablaMed').rows.length;i++){
for (var j=0;j<4;j++){
if (j==3){
textos = textos + document.getElementById('TablaMed').rows[i].cells[j].childNodes[0].value;
}else{
textos = textos + document.getElementById('TablaMed').rows[i].cells[j].childNodes[0].value + '-';
}
}
textos = textos + '/';
}
alert(textos);
document.getElementById("OcultoDatoTabla").value = textos;
}

</script>

<style type="text/css">
<!--
.Estilo1 {font-size: 12px}
.TEXTO { font-family: Arial, Helvetica, sans-serif;
font-size: 12px;
font-style: normal;
line-height: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
color: #FFFFFF;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="get" action="dos.php">
<table width="372" border="1" id="TablaMed">
<tr class="Estilo1">
<td width="149">Nombre de Medicamento </td>
<td width="28">Cant</td>
<td width="58">Dosis</td>
<td width="109">Observacion</td>
</tr>
</table>
<p>
<input name="AgregaMed" type="button" id="AgregaMed" value="+" onclick="agregar()" />
<input name="EliminarMed" type="button" id="EliminarMed" value="-" onclick="eliminarultima()" />
<input name="OcultoContLin" type="text" size="3" id="OcultoContLin" style="visibility:visible" />
<input name="Mostrar" type="button" id="Mostrar" value="mostrar" onclick="datosTextos()" />
<input name="OcultoDatoTabla" type="text" size="40" id="OcultoDatoTabla" style="visibility:visible" />
<input name="cadena" type="submit" id="cadena" value="cadena"/>
</p>
</form>
<p> </p>
</body>
</html>

//////este es el codigo dos.php el cual recibe todos los datos de los campos creados, nada mas falta realizar la suma de la dosis
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<?php
$cadena = $_GET['OcultoDatoTabla'];
$partes = explode("/",$cadena); // divide una cadena segun separador
array_pop($partes); // elimina el ultimo elemento del array
for($i=0;$i<=(count($partes)-1);$i++){
$subpartes = explode("-",($partes[$i]));
}

for($i=0;$i<=(count($partes));$i++)
{
echo $partes[$i];
echo "<br>";
}

echo "<pre>";
var_dump($partes);
echo "</pre>";

$i = 0;
foreach($partes as $v) {
print "\$a[$i] => $v<br>";
$i++;
}
echo 'cantidad total=';
?>

<body>
</body>
</html>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:programacion php y javascript

Publicado por Jose Alvarado (17 intervenciones) el 18/06/2010 01:35:43
Daniel,

¿Deseas sumar la columna de las dosis ? si es asi ¿porque tienen una "t" al inicio del numero?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:programacion php y javascript

Publicado por Daniel (2 intervenciones) el 18/06/2010 03:12:44
de hecho quiero sumar las cantidades que sean, y que en la segunda pagina me de el resultado de dicha suma, las "t" son para identificarlas, pero ese no debe de ser el dato que se envia, sino que un valor
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar