| | |
Problem with PhP MySql Ajax dropdown script
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2009
Posts: 2
Reputation:
Solved Threads: 0
HI, I am using Roshan's Ajax dropdown code for my two ajax dropdown menus.
All is working fine, but when I want to use $_POST in the submitted form with FireFox, its not working...??? Its working fine in IE.
Can anybody please help me with this problem?
The Form where the dropdown is:
The townsrc.php:
The submit for:
In IE $province and $city gets posted
In FF only $province gets posted
Can it maybe something got to do with the <div>????
All is working fine, but when I want to use $_POST in the submitted form with FireFox, its not working...??? Its working fine in IE.
Can anybody please help me with this problem?
The Form where the dropdown is:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!-- Province goes here --> <tr> <td>-</td><td>-</td><td>-</td><td>-</td><td>Province</td><td> <select name="province" onChange="getCity('../dir/townsrc.php?province='+this.value)"> <option value="">Select Province</option> <option value="1">KwaZulu-Natal</option> <option value="2">Western Cape</option> <option value="3">Eastern Cape</option> <option value="4">Free State</option> <option value="5">Gauteng</option> <option value="6">Limpopo</option> <option value="7">Mpumalanga</option> <option value="8">North West</option> <option value="9">Northern Cape</option> </select> </td> </tr> <!-- Province ends here --> <!-- Town goes here --> <tr> <td>-</td><td>-</td><td>-</td><td>-</td><td>Town</td><td> <div id="citydiv"><select name="city"> <option>Select Town</option> </select> </div> </td> </tr> <!-- Town ends here -->
The townsrc.php:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<? $country=intval($_GET['province']); $query=("SELECT * FROM search_town WHERE provId=$country ORDER BY townLabel ASC"); $result=mysql_query($query); ?> <select name="city"> <option>Select Town</option> <? while($row=mysql_fetch_array($result)) { ?> <option value><?=$row['townLabel']?></option> <? } ?> </select>
The submit for:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
$province = trim($_POST['province']); $city = trim($_POST['city']);
In FF only $province gets posted
Can it maybe something got to do with the <div>????
Try to run this document inside your server w/o adding or changing anything:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<?xml-stylesheet type="text/css" href="#css21" media="screen"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html id="xhtml10S" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://www.w3.org/2005/10/profile">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<meta http-equiv="Window-target" content="_top" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<title>Free Live Help!</title>
<style id="css21" type="text/css" media="screen">
/* <![CDATA[ */
td { text-align : center; }
/* ]]> */
</style>
<script id="javascript1.5" type="text/javascript">
// <![CDATA[
var getCity = function( method, qstr ) {
var sel = (( document.getElementsByTagName ) ? document.getElementsByTagName("select") : document.all.tags("select"));
sel1 = sel[ (( typeof this.id !== "undefined" ) ? this.id : qstr ) ];
qstr = sel1.options[ sel1.selectedIndex ].value;
sel2 = sel[ "city" ].options[ sel[ "city" ].selectedIndex ].value;
url = (( method === "GET" ) ? "../dir/townsrc.php?province=" + qstr + "&city=" + sel2 : "../dir/townsrc.php" );
try {
if ( "XMLHttpRequest" in window ) {
xmlHttp = new XMLHttpRequest();
} else if ( "ActiveXObject" in window ) {
var client = [ "MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP" ];
try {
for ( var i = 0; i < client.length; i++ ) {
xmlHttp = new ActiveXObject( client[ i ] );
}
} catch( er ) { }
}
} catch( e ) {
if ( "createRequest" in window ) {
xmlHttp = window.createRequest();
} xmlHttp = null;
} if ( xmlHttp !== null ) {
(( "overrideMimeType" in xmlHttp ) ? xmlHttp.overrideMimeType("text/xml") : xmlHttp );
xmlHttp.onreadystatechange = function() { // I have no idea on how you implement things inside here.
/* So you'll need to re-implement everything to get what you exactly needed on this operation.
inititializing normal operation: */
if ( xmlHttp.readyState === 4 || xmlHttp.readyState === "complete" ) {
if ( xmlHttp.status === 200 ) {
(( document.getElementById ) ? document.getElementById("citydiv") : document.all.citydiv ).innerHTML = xmlHttp.responseText;
}
}
};
xmlHttp.open( method, encodeURIComponent( url ), true );
(( method === "POST" && "setRequestHeader" in xmlHttp ) ? xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8;") : xmlHttp );
xmlHttp.send((( method === "POST" ) ? "province=" + qstr + "&city=" + sel2 : null ));
return false;
} alert( "Your browser does not handle AJAX Request!" );
};
// ]]>
</script>
</head>
<body>
<div id="main">
<form id="form" action="#" onsubmit="return false;">
<table width="50%" frame="box" rules="all" cellpadding="4" cellspacing="4" border="1">
<!-- Province goes here -->
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>Province</td>
<td><!-- The following request type can be set to "GET/POST" inside the getCity() function request builder.
Just see which one works in your form -->
<select id="province" name="province" onChange="getCity( 'GET', 'province' );" size="1">
<option value="">Select Province</option>
<option value="1">KwaZulu-Natal</option>
<option value="2">Western Cape</option>
<option value="3">Eastern Cape</option>
<option value="4">Free State</option>
<option value="5">Gauteng</option>
<option value="6">Limpopo</option>
<option value="7">Mpumalanga</option>
<option value="8">North West</option>
<option value="9">Northern Cape</option>
</select>
</td>
</tr>
<!-- Province ends here -->
<!-- Town goes here -->
<tr>
<td>-</td>
<td>-</td>
<td>-</td>
<td>-</td>
<td>Town</td><td><div id="citydiv">
<select id="city" name="city" size="1"><option value="" selected="selected">Select Town</option>
</select>
</div>
</td>
</tr>
</table>
<!-- Town ends here -->
</form>
</div>
</body>
</html> Last edited by essential; Jul 5th, 2009 at 1:05 am.
![]() |
Similar Threads
- Looking for PHP / MySQL Developer (Web Development Job Offers)
- Looking for a PHP/MYSQL Programmer (Web Development Job Offers)
- Need Highly Experienced PHP/MySQL Programmer $15-$25/hour (Web Development Job Offers)
- Urgent: PHP, MySQL, AJAX Developer (Web Development Job Offers)
- [For Hire] PHP, Mysql, ASP, AJAX, DHTML programer (Post your Resume)
- Online Database - PHP/ MYSQL (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Streaming Video
- Next Thread: AJAX app not working in IE6, IE7, or IE8 I think JS file is problem
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser captchaformproblem cart checkbox child close codes css debugger decimal dependent disablefirebug dom download editor element engine enter error events explorer ext file firefox form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math media menu microsoft mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player position problem programming prototype redirect regex runtime safari scale scriptlets search security select shopping size software sql textarea unicode w3c window windowofwords wysiwyg \n





