(Formulario)
Código HTML:
</script> <form method='GET' action='/get_city_state.php'> <input type='text' name='zip' size='20'></p> <p><input type='text' name='city' size='20'></p> <p><input type='text' name='state_abbr' size='20'></p> <p><input type='submit' value='Enviar' name='B1'></p> </form>
(Codigo que hace las llamadas)
Código PHP:
<script>
var ajax = getHTTPObject();
function getHTTPObject()
{
var xmlhttp;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else if (window.ActiveXObject) {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} else {
//alert("Your browser does not support XMLHTTP!");
}
return xmlhttp;
}
function updateCityState()
{
if (ajax)
{
var zipValue = document.getElementById("zipcode").value;
if(zipValue)
{
var url = "/get_city_state.php";
var param = "?zip=" + escape(zipValue);
ajax.open("GET", url + param, true);
ajax.onreadystatechange = handleAjax;
ajax.send(null);
}
}
}
function handleAjax()
{
if (ajax.readyState == 4)
{
citystatearr = ajax.responseText.split(",");
var city = document.getElementById('city');
var state = document.getElementById('state');
city.value = citystatearr[0];
state.value = citystatearr[1];
}
}
</script>
Que le debo agregar a mi formulario para que realice las llamadas Ajax
En estos campo que debo de agregar.
Código:
Saludos <input type='text' name='zip' size='20'> <input type='text' name='city' size='20'> <input type='text' name='state_abbr' size='20'> <input type='submit' value='Enviar' name='B1'>