Foros del Web » Programando para Internet » PHP »

Usar misma variable de Javascript en PHP

Estas en el tema de Usar misma variable de Javascript en PHP en el foro de PHP en Foros del Web. Hola a todos. En el siguiente código, lo que pretendo hacer es lo siguiente: Con PHP tengo unas variables que me arrojan una cantidad. Esa ...
  #1 (permalink)  
Antiguo 07/12/2014, 14:20
Avatar de julibaga  
Fecha de Ingreso: abril-2007
Mensajes: 40
Antigüedad: 17 años
Puntos: 0
Pregunta Usar misma variable de Javascript en PHP

Hola a todos.
En el siguiente código, lo que pretendo hacer es lo siguiente:
Con PHP tengo unas variables que me arrojan una cantidad. Esa cantidad la quiero multiplicar por un número que yo le tengo que poner en un input y me tiene que arrojar el resultado en el tercer campo.
Esta operación es doble porque son dos variable distintas las que tomo del PHP. Lo que necesito es que al poner en el input 100 (por ejemplo), me dé el resultado en las dos como si repitiera 100 en el segundo cálculo.

Código PHP:
<script type="text/javascript">
//<![CDATA[
 
function calcula(operacion){ 
var cantidad = document.getElementById('CANTIDAD').value; 
var cantidad_decimal = parseFloat(cantidad); 
var precio = document.getElementById('PRECIO').innerHTML;
 var decimal = parseFloat(precio); 
var subtotal = cantidad * decimal 
document.getElementById('SUBTOTAL').value = subtotal 
}
function calcula2(operacion){ 
var cantidad2 = document.getElementById('CANTIDAD2').value; 
var cantidad_decimal2 = parseFloat(cantidad2); 
var precio2 = document.getElementById('PRECIO2').innerHTML;
 var decimal2 = parseFloat(precio2); 
var subtotal2 = cantidad2 * decimal2 
document.getElementById('SUBTOTAL2').value = subtotal2

}
 
//]]>
</script>
<center>
<font size="4"><b>Calculate the price of your property.</b></font>
<br /><font size="3">How many m² does the LOT you want to price have.. type the number in the blank.</font><br /><br />
<font size="4"><table>
<tr>
<td>Average Selling Price per m² is $</td>
<td>
<div style = "vertical-align:middle" id="PRECIO"><?php echo number_format(($sellingprice $i)/($sumlot $i),0,'.',',');?></div>
</td>
<td>&nbsp;x&nbsp;</td>
<td><input style="width:80px; fonf-weight:bold; font-size:12pt;" type="text" name="CANTIDAD" id="CANTIDAD" value="" onkeyup="calcula()" /></td>
<td>m²&nbsp;&nbsp;=&nbsp;&nbsp;$</td></font>
<td><input style="width:80px; fonf-weight:bold; font-size:12pt;" type="text" name="SUBTOTAL" id="SUBTOTAL" value="" readonly size="9" /></td>
</tr>
</table>
</font>
</center>

<center>
<font size="4"><table>
<tr>
<td>Average Asking Price per m² is $</td>
<td>
<div style = "vertical-align:middle" id="PRECIO2"><?php echo number_format((($sumprice $i)/($sumlot $i)),0,'.',',');?></div>
</td>
<td>&nbsp;x&nbsp;</td>
<td><input style="width:80px; fonf-weight:bold; font-size:12pt;" type="text" name="CANTIDAD2" id="CANTIDAD2" value="" onkeyup="calcula2()" /></td>
<td>m²&nbsp;&nbsp;=&nbsp;&nbsp;$</td></font>
<td><input style="width:80px; fonf-weight:bold; font-size:12pt;" type="text" name="SUBTOTAL2" id="SUBTOTAL2" value="" readonly size="9" /></td>
</tr>
</table>
</font>
</center>
Gracias.

Etiquetas: html, javascript, usar, variable
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 02:54.