Hello,
I have a very simple page that has an “onblur” that calls an ajax function.
Once the value from that select object when changed the ajax function calls a php page that fetchs the data from SQL and returns new HTML code with a new drop-down menu (select object).
once I post or even get the values the returned value (which is visible on the page, doesn’t get forwarded into the post / get).
When I post these are the values I get:
Array (
[country] => 1
[cname] => somestate
[AddCity] => Add City
)
Here is the code for all of it:
First PHP Page:
[code]
<?php
session_start();
if (!isset($_SESSION[‘login’])) {
header(“location: login.php”); exit;
}
global $DB, $INFO;
require (‘conf/db.class.php’);
$DB = new dbCon;
$DB->link[‘dbname’] = $INFO[‘dbname’];
$DB->link[‘dbuser’] = $INFO[‘dbuser’];
$DB->link[‘dbpass’] = $INFO[‘dbpass’];
$DB->link[‘dbhost’] = $INFO[‘dbhost’];
$DB->dbConnect();
$mode = $_GET[‘view’];
?>
<!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=iso-8859-1″>
<meta http-equiv=”imagetoolbar” content=”no”>
<meta name=”distribution” content=”global” />
<meta name=”revisit” content=”10 days” />
<meta name=”revisit-after” content=”10 days” />
<meta name=”resource-type” content=”document” />
<meta name=”audience” content=”all” />
<meta name=”rating” content=”general” />
<meta name=”robots” content=”all” />
<meta name=”robots” content=”index, follow” />
<meta name=”language” content=”en” />
<meta name=”country” content=”US” />
<title>Add City</title>
<script type=”text/javascript” src=”<?=$INFO[‘siteaddr’]?>scripts/selectstate.js”></script>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″>
<center>
<table width=”300″ cellpadding=”0″ cellspacing=”0″ align=”center”>
<tr><td align=”center”><br />
<? if ($mode == “window”) {
if($_POST[‘AddCity’] == “Add City”) {
$country = $_POST[‘country’];
$states = $_POST[‘state’];
$city = $_POST[‘cname’];
print_r($_POST);
} // Close Post ?>
<fieldset>
<legend>Add City</legend>
<table cellpadding=”0″ cellspacing=”0″ align=”left”>
<form name=”AddCities” method=”POST”>
<tr>
<td>Country: </td>
<td>
<select name=”country” style=”width: 146px” onblur=”showState(this.value);”>
<option value=”0″ selected=”selected”> </option>
<? $sql = “select * from `countries` ORDER BY `sortorder`”;
$result = $DB->query($sql);
while($row = mysql_fetch_array($result)) { ?>
<option value=”<?=$row[0]?>”><?=ucwords($row[1])?></option>
<? }?>
</select>
</td>
</tr>
<tr>
<td>State: </td>
<td>
<div id=”txtstate”>
<select name=”state” id=”state” style=”width: 146px;”>
<option value=”0″ selected=”selected”> </option>
</select>
</div>
</td>
</tr
selectstate.js code:
[code]
var xmlhttpco;
function showState(str)
{
xmlhttpco=GetXmlHttpObject();
if (xmlhttpco==null)
{
alert (“Browser does not support HTTP Request”);
return;
}
var url=”getstate.php”;
url=url+”?q=”+str;
url=url+”&sid=”+Math.random();
xmlhttpco.onreadystatechange=stateChangedco;
xmlhttpco.open(“GET”,url,true);
xmlhttpco.send(null);
}
function stateChangedco()
{
if (xmlhttpco.readyState==4)
{
document.getElementById(“txtstate”).innerHTML=xmlhttpco.responseText;
}
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject(“Microsoft.XMLHTTP”);
}
return null;
}
getstate.php code:
[code]
<?php
session_start();
global $DB, $INFO;
require (‘conf/db.class.php’);
$DB = new dbCon;
$DB->link[‘dbname’] = $INFO[‘dbname’];
$DB->link[‘dbuser’] = $INFO[‘dbuser’];
$DB->link[‘dbpass’] = $INFO[‘dbpass’];
$DB->link[‘dbhost’] = $INFO[‘dbhost’];
$DB->dbConnect();
$q=$_GET[‘q’];
$sql=”SELECT * FROM `states` WHERE `countryid` = ‘”.$q.”‘ ORDER BY `sname`”;
$result = $DB->query($sql);?>
<select name=”state” id=”state” style=”width: 146px;” onchange=”showCity(this.value);showKeywords(this.value);showKeywords2(this.value);showKeywords3(this.value);showKeywords4(this.value);”>
<option value=”0″ selected=”selected”> </option>
<? while($row = mysql_fetch_array($result)) { ?>
<option value=”<?=$row[0]?>”><?=ucwords($row[1])?></option>
<? } ?>
</select>
Any and all help will be much appreciated.