I implemented a search form that has 3 drop down <select>
tags
The first 2 drop downs have static options while I used a javascript to create the options of the third drop down. The javascript is based on onchange
event of 2nd drop down and is stored in searchideas.js
file
This searchideas.js
file calls datasupplier.php
using GET
method through XMLHttpRequest
. All works fine on my localhost but when I hosted it on the live website, the options for the third drop down does not gets generated. xmlhttp.readyState
becomes 4
but xmlhttp.status
becomes 500
which corresponds to Internal server error.
I have also moved the searchideas.js
and datasupplier.php
in the same folder where my webpage containing the dropdowns is located but to no avail.
How can I over come this error?
My searchideas.js
is:
function searchideas( )
{
var state = document.getElementById("stateID").value;
var county = document.getElementById("countyID").value;
var town = document.getElementById("townID").value;
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var selectList = document.getElementById('townID');
var val = xmlhttp.responseText;
var jsonData = JSON.parse(val);
for (var i in jsonData)
{
var option = document.createElement('option');
option.value = "http://www.mywebsite.com" + i;
option.text = jsonData[i];
selectList.appendChild(option);
}
}
}
var url = "http://www.mywebsite.com/sites/all/themes/danland/datasupplier.php?stateID=" + state + "&countyID=" + county + "&townID=" + town;
xmlhttp.open("GET",url,true);
xmlhttp.send();
}
My datasupplier.php
is:
<?php
$stateID = $_GET['stateID'];
$countyID = $_GET['countyID'];
$townID = $_GET['townID'];
$states = array();
$states['SC'] = "Stories";
$states['TL'] = "Novels";
$counties = array();
$counties['SC']['PRACT'] = 'By Interest';
$counties['SC']['SERV'] = 'By Choice';
$counties['TL']['PRACT'] = 'By Interest';
$counties['TL']['SERV'] = 'By Choice';
$towns = array();
$towns['SC']['PRACT']['/index.php?q=sc%3Fpract%3Ffai'] = "Fairy Tale";
$towns['SC']['PRACT']['/index.php?q=sc%3Fpract%3Fedu'] = "Education";
$towns['SC']['SERV']['/index.php?q=sc%3Fserv%3Ffic'] = "Fiction";
$towns['TL']['PRACT']['/index.php?q=tl%3Fpract%3Fzom'] = "Zombie";
$towns['TL']['PRACT']['/index.php?q=tl%3Fpract%3Fedu'] = "Education";
$towns['TL']['SERV']['/index.php?q=tl%3Fserv%3Fsal'] = "Sales";
$towns['TL']['SERV']['/index.php?q=tl%3Fserv%3Fstr'] = "Strategy";
if($stateID && !$countyID && !$townID)
{
echo json_encode( $counties[$stateID] );
}
elseif( $stateID && $countyID && !$townID )
{
echo json_encode( $towns[$stateID][$countyID] );
}
elseif( isset($villages[$stateID][$countyID][$townID]) )
{
echo json_encode( $villages[$stateID][$countyID][$townID] );
}
else
{
echo '{}';
}
?>