![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
13/01/2016, 12:36
|
| | Fecha de Ingreso: diciembre-2015
Mensajes: 45
Antigüedad: 9 años, 2 meses Puntos: 3 | |
Respuesta: Actualizar Variables sin Recargar Hola hermano, yo lo haría de esta manera aunque también ocupo JQuery, el chiste de lograr lo que quieres es poner tu código en los eventos correspondientes y con eso funcionará.
Archivo index.php
<!DOCTYPE html>
<html>
<head>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
if ( typeof XMLHttpRequest == "undefined" )
XMLHttpRequest = function(){return new ActiveXObject(navigator.userAgent.indexOf("MSIE 5") >= 0 ?"Microsoft.XMLHTTP" : "Msxml2.XMLHTTP2");};
var ajax=new XMLHttpRequest();
function miFuncion2(){
var x = document.getElementById("mySelect").value;
var y = document.getElementById("mySelect2").value;
ajax.open("POST","funcionXY.php",true);
ajax.onreadystatechange=function(){
if(ajax.readyState==4){
var respuesta=ajax.responseText;
document.getElementById('demo').innerHTML=respuest a;
}
}
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send("x="+x+"&y="+y);
}
$(document).ready(function(){
$('#mySelect2 > option[value="1"]').attr('selected', 'selected');
miFuncion2();
});
</script>
</head>
<select id="mySelect2" onchange="miFuncion2()">
<script>
var i=0
for (i=0;i<=10;i++){
document.write("<option value='"+i+"'>" + i)
}
</script>
</select>
<input type="text" id="mySelect" onchange="miFuncion2()" value="8990">
El total es <div id="demo"></div>
</body>
Archivo funcionXY.php
<?php
$y = $_POST['y'];
$x =$_POST['x'];
function insertar($x, $y) {
$z=$y*$x;
return $z;
}
echo "<p>".insertar($x, $y)."</p>";
?>
Yo uso 2 archivos uno para mi funcion y otro el index, es costumbre poner mis funciones por separado mi código funciona incluso en internet explorer, el código que colocaste anteriormente no. Éxitos sigue adelante. |