1 Replies - 322 Views - Last Post: 29 October 2011 - 12:05 PM

#1 saxasm  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 38
  • Joined: 30-May 08

AJAX loading of next question in form not working

Posted 28 October 2011 - 08:34 AM

So, my javascript:
<script type="text/javascript">
function stopselect(county)
{
   request = new XMLHttpRequest();
   request.open('GET',concat('warnajax.php?county=',county),false);
   request.send();
   document.getElementById("stopselection").innerHTML=request.responseText;
}
</script>

I have checked, and the event catch most definitely works and this function is called.

warnajax.php is extremely simple:
<?php
echo $_GET['county'];
?>


The code that prints the form in question looks like:
<?php
include("mysqlconnect.php");
$query = "SELECT DISTINCT county FROM rawxmldata ORDER BY county;";
$result = mysql_query($query) or die(mysql_error());
echo '<form method="post" action="createwarn.php">Välj kommun: <select onchange="stopselect(this.options[this.selectedIndex].value)" name="county">';
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
   $county = preg_split("/ /",$row['county']);
   $countyname = $county[0].$county[1];
   echo '<option value="'.$countyname.'">'.$row['county']."</option>
   ";
}
echo "</select>";
echo '<div id="stopselection"></div>';
echo "</form>";
?>


I'm an extreme noob at all AJAX and javascript things, so the only thing I've tried so far is removing all superfluous code. It should load another <select> letting the user select what bus stop in the county to choose, once it is done. Anyone able to see why it fails?

Is This A Good Question/Topic? 0
  • +

Replies To: AJAX loading of next question in form not working

#2 VolcomMky  Icon User is offline

  • D.I.C Regular

Reputation: 74
  • View blog
  • Posts: 315
  • Joined: 13-May 09

Re: AJAX loading of next question in form not working

Posted 29 October 2011 - 12:05 PM

Is it hitting the ajax page with the full url?

"The concat() method is used to join two or more arrays.

This method does not change the existing arrays, it only returns a copy of the joined arrays."
- W3Schools

I would replace this
request.open('GET',concat('warnajax.php?county=',county),false);
with this
request.open('GET','warnajax.php?county='+county,false);

This post has been edited by VolcomMky: 29 October 2011 - 12:05 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1