<script type="text/javascript">
function bindCity() {
// Some javascript code
//declare options array and populate
var modelnames = new Array();
$.get("file.php?mt=" + qs, function(data) {
eval(data);
if(modelnames.length > 0) {
addOptions(modelnames);
}
}
);
}
function addOptions(cl) {
//enable child select and clear current child options
$("#mn").removeAttr("disabled");
$("#mn").html('');
//repopulate child list with array from helper page
var city = document.getElementById('mn');
for(var i = 0; i < cl.length; i++) {
city.options[i] = new Option(cl[i].text, cl[i].value);
}
}
</script>
This is the PHP script (After getting the values to $mt):-
$SQLqueryTry = "SELECT mn FROM pd WHERE pd_mt = '$mt'";
$SQLqueryETry = mysql_query($SQLqueryTry, $dacreint) or die(mysql_error());
while ($Try = mysql_fetch_array($SQLqueryETry))
{
$output = "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";
}
My output code in PHP file:-
header('Content-type: text/plain');
echo $output;
Now i am able to fetch only one value when it is $output = "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";
However when i add . to $output =, to make it $output .= "modelnames.push(new Option('$Try[mn]', '$Try[mn]'));\n";
I am unable to get any value. What is the problem?
Are you able to see any errors in your error log?
My first guess is that you’ve forgotten to initialize the
$outputvariable before using.=on it.Maybe try: