Location: PHPKode > scripts > Free PHP Ajax Yahoo Weather API > free-php-ajax-yahoo-weather-api/index.php
<?php
/*
This script was downloaded at:
LightPHPScripts.com
Please support us by visiting
out website and letting people
know of it.
Produced under: LGPL
*/

// Get options
include('configs.php');

// Search zipcode
if($_GET['zipcode2'] != NULL){
	$zip_code = $_GET['zipcode2'];
} else {
	$zip_code = $_GET['zipcode'];
}


if($USE_DATA){
	// Include database
	include_once('database.php');
} else {
	// Include state List
	include_once('state_list.php');
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ajax Weather Script By LightPHPScripts.com</title>
<script language="javascript">

// Get HTTP Request
var http;
if (!http && typeof XMLHttpRequest != 'undefined') {
	try {
		http = new XMLHttpRequest();
	} catch (e) {
		http = false;
	}
}
	
// Actual Ajax call
function doAjax(optionDo)
{
	var imageCode = '<br /><div align="center"><img src="pleaseWait.gif"></div>';
	
	// Doing states
	if(optionDo == 1)
	{
		var state = document.getElementById('state').value;
		if(state != '')
		{

			http.open("GET", 'ajax.php?state='+state, true);
			http.onreadystatechange = handleHttpResponse;
			http.send(null);
		}
	}
	// Doing it by zipcode (via city)
	if(optionDo == 2)
	{
		var zipcode = document.getElementById('zipcode2').value;
		if(zipcode != '')
		{
			document.getElementById('showFinal').innerHTML = imageCode;
			http.open("GET", 'ajax.php?zip_code='+zipcode, true);
			http.onreadystatechange = handleHttpResponseFinal;
			http.send(null);
			document.getElementById('zipcode').value = zipcode;
		}
	}
	// Doing it by zipcode
	if(optionDo == 3)
	{
		var zipcode = document.getElementById('zipcode').value;
		if(zipcode != '')
		{
			document.getElementById('showFinal').innerHTML = imageCode;
			http.open("GET", 'ajax.php?zip_code='+zipcode, true);
			http.onreadystatechange = handleHttpResponseFinal;
			http.send(null);
		}
	}
}	
	
// Response handler for state list
function handleHttpResponse()
{
	if (http.readyState == 4)
	{
		var response = http.responseText;				
		document.getElementById('showStates').innerHTML = response;
	}	
}

// Response handler to show final weather information
function handleHttpResponseFinal()
{
	if (http.readyState == 4)
	{
		var response = http.responseText;				
		document.getElementById('showFinal').innerHTML = response;
	}	
}
</script>
</head>
<body onLoad="doAjax('3');">
<form name="reload" id="reload" style="display:inline;">
  <table width="790"  border="1" align="center" cellpadding="3" cellspacing="2" bordercolor="#990000">
    <tr>
      <td bgcolor="#FFE6E6"><div align="center"><strong>Please select city: </strong></div></td>
    </tr>
    <tr>
      <td><div align="center">
        <select name="state" id="state" onChange="doAjax('1');">
		<option value=""></option>
		<?=$state_list_form;?>
        </select>
		<div id="showStates"></div>
		
		<br/>
or Enter ZipCode: 
<input name="zipcode" type="text" id="zipcode" value="<?php echo $_GET['zipcode'];?>" onBlur="doAjax('3');"> 
 <div id="showFinal"></div>
      </div></td>
    </tr>
    <tr>
      <td><div align="right"><a href="http://www.LightPHPScripts.com" target="_blank"><font size="1"><strong>Powered By LPS</strong></font></a> </div></td>
    </tr>
  </table>
</form>
<!--
This script was downloaded at:
LightPHPScripts.com
Please support us by visiting
out website and letting people
know of it.
Produced under: LGPL
-->
</body>
</html>
Return current item: Free PHP Ajax Yahoo Weather API