0

Okay I'm currently using AJAX to update part of my site when a drop down box is changed, but I'm having trouble passing the parameters to be usable by the function.

Here is the HTML:

<script type='text/javascript' src='ajax.js'></script> //Where to find function

<div id="combobox" style="width: 150px; height: 300px; overflow-y: scroll">
  <select onchange="MakeRequest(test); location = this.options[this.selectedIndex].value;"> 
    <option>Races</option>

    <?php ComboBox() ?>
  </select>
   .
   .

Here is the AJAX function in external ajax.js file:

function MakeRequest(test) {
  var linkInfo = "teleport.php?call=" + test;
  var xmlHttp = getXMLHttp();

  xmlHttp.onreadystatechange = function() {
    if (xmlHttp.readyState == 4) {
      HandleResponse(xmlHttp.responseText);
    }
  }

  xmlHttp.open("GET", linkInfo, true);
  xmlHttp.send(null);
}

How would I get this working?

3 Answers 3

1
location=this.options[this.selectedIndex].value

This is changing the page to a different location. That is not AJAX, remove it.

Instead, put that this.options[this.selectedIndex].value (or just this.value - same thing) what you put test.

Sign up to request clarification or add additional context in comments.

Comments

0

Ajax nature is asynchronous. I guess you want to first send an AJAX request to the server, and on the result of its response, redirect user on the client side to another page.

What happens in your code, is that first of all, MakeRequest() function is called, but it's immediately returned back (because ajax is asynchronouse), thus the next part of the onchange attribute would be called, and user would be redirected to another page.

To test, make your ajax call synchronous. See here.

Comments

0
<select onchange="MakeRequest(this.value); " />

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.