BennyTheBunny
Programmer
Let's start out with a Howdy and a Thanks! for any suggestion you may have.
This is an existing PHP/javaScript/Ajax system used by a note-for-profit for whom I'm working pro bono. Converting to jQuery isn't a practical solution do to costs and size of the code base.
Chrome's Mac version seems to have an issue with PHP/Javascript and passing variables such is 'This.value'.
It appears it passes the data but what is passes is the error for 'undifined veriable'.
Interesting that there is no issue under windows with Chrome, IE, firefox (didn't check Safari)
And on a Mac it works with IE and Firefox but not with Chrome or Safari.
However, it's easly to demonstrate that the 'This.value' , in [highlight #FCE94F]<select name="state" id="state" onclick="showTown(this.value,'all',false)" >[/highlight], is not reaching the javascript 'showTown' in the case of MAC Chrome.
So, this is what I'm assuming - 'This.value' is for some reason seen by Chrome's Mac version as 'undifined' and is being corrupted.
Code involved:
on a php page there is the following code segment(note the <select name='state'...> line ):
<div class="selectFilter">
<span class="tableLabel">State:</span>
<!-- Very important that 'onclick' instead of 'onchange' as when states are changed it would trip the showTown -->
<!-- <select name="state" id="state" onclick="showTown(this.value)"> -->
[highlight #FCE94F] <select name="state" id="state" onclick="showTown(this.value,'all',false)" >[/highlight]
<option value="all">All</option>
<?php
include "./support/stateslist.php";
?>
</select>
</div>
<div class="clearing" style="height: 7px;"> </div>
<div class="selectFilter">
<div id="listCities"></div>
</div>
When the 'onclick' event occurs it passes variables to a called javaScript.
function showTown(str, cty, fistPass)
{
if (str=="")
{
document.getElementById("listCities").innerHTML="";
return;
}
if (window.XMLHttpRequest){
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("listCities").innerHTML=xmlhttp.responseText;
document.getElementById("devType").value = 'all';
//newTotals(str,'all','all');
if (cty=="")
{
newTotals(str,'all','all');
}else{
newTotals(str,cty,'all');
}
}
}
xmlhttp.open("GET","support/getCity2.php?state="+str+"&city="+cty+"&firstPass="+fistPass,true);
xmlhttp.send(null);
}
And the above is used to power this PHP:
<?php
include "support.php";
$state=$_GET['state'];
$city=$_GET['city'];
$OnLoad=$_GET['firstPass'];
$preloadedcity = '';
?>
<span class="tableLabel">Town:</span>
<select name="city" id="city" onChange="handleForm()">
<option value="all">All</option>
<?php
$citySQL="SELECT DISTINCT(city) FROM tblproject where state like '$state' ORDER BY city ASC";
$cityResult=mysql_query($citySQL);
for ($x=0;$x<mysql_num_rows($cityResult);$x++) {
$cityDetail=mysql_fetch_array($cityResult);
if((strtoupper($cityDetail[city])== strtoupper($city)) && ( $OnLoad == true) ){
$preloadedcity = "selected";
}else{
$preloadedcity = "";
}
echo "<option name='city' id='city' $preloadedcity value='$cityDetail[city]'>$cityDetail[city]</option>";
}
?>
</select>