Ver Mensaje Individual
  #6 (permalink)  
Antiguo 18/03/2012, 12:09
Avatar de Lynxcraft
Lynxcraft
 
Fecha de Ingreso: noviembre-2007
Ubicación: yecla murcia
Mensajes: 1.346
Antigüedad: 17 años, 3 meses
Puntos: 51
Respuesta: Variables tomada con php no puedo sumarlas con javascript

yo lo haría de esta forma
Código 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>Tu Dieta</title>
<p align="center"><b>Selecci&oacute;n y adici&oacute;n de elementos a una lista
<script language="javascript">
var valor_total = 0;
var _list_kalorias = new Array();

function insertar_el_numero(op) {
    var chosenoption=op.options[op.selectedIndex] //this refers to "selectmenu"
    if (!isNaN(chosenoption.value)){
         _list_kalorias.push(chosenoption);
         calculate();
    }
}
function calculate(){
    var form = document.getElementById('form-carnes');
    var txt='';
    valor_total=0;
    for(var i =0;i<_list_kalorias.length;i++ ){
        var op = _list_kalorias[i];
        txt+=op.text +':'+op.value+"\n"; 
        valor_total += parseInt(op.value);
    }
    form.seleccionados.value=txt;
    form.suma.value=valor_total;
}

// End -->
</script>
</head>
</b>
<body style="font-family: Verdana">
</p>
<form id="form-carnes" name="formularios" action=""/>
<select name="form_carnes" onchange="insertar_el_numero(this);"/>
<?php
mysql_query 
("SET NAMES 'utf8'");
do {
?>
<option value="<?php echo $row_registro['kilocalorias'?>"><?php echo $row_registro['nombre']?></option>
<?php
} while ($row_registro mysql_fetch_assoc($registro));
$rows mysql_num_rows($registro);
if(
$rows 0) {
mysql_data_seek($registro0);
$row_registro mysql_fetch_assoc($registro);
}
?>

</select><font face="Arial, Helvetica, Sans Serif" size="2">Elementos a&ntilde;adidos a la lista:</font><br>
<textarea cols="40" rows="10" name="seleccionados"></textarea>
<textarea cols="10" rows="10" name="suma"></textarea>
</form>
__________________
Sobran las ideas cuando faltan ganas de trabajar en ellas
Lynxcraft