0

Okay, I've been struggling with this for a few hours now. I'm using ajax to update a div in my site with a php code however, i'm trying to send parameters in the function from the external javascript file to update the correct link(there are multiple drop down boxes)

for example: this is my select box

<script type='text/javascript' src='ajax.js'></script>//include ajax file
<select onchange='MakeRequest(raceupdate);
        this.options[this.selectedIndex].value;'> //so no use of a button is needed to auto link to anchor tag
        <option>Deathmateched</option>
    <?php
        dmList()
        ?>

 </select>

Then next my external ajax function MakeRequest().

function MakeRequest(value)
{
    var linkInfo = "teleport.php?call=" + value;//create appropriate link depending on function parameters  
    var xmlHttp = getXMLHttp();

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

    xmlHttp.open("GET", linkInfo, true); //update page using link info variable created above
    xmlHttp.send(null);

}

So as you can see I'm trying to pass a sting of text into this function, but I seem to be failing somewhere.

4
  • Why don't you post what error messages you're getting? Commented May 31, 2012 at 0:57
  • the 'value' variable is been passed as undefined if I put it in an alert box Commented May 31, 2012 at 1:00
  • 1
    Are you trying to pass the string "raceupdate" to MakeRequest or is there a variable somewhere called raceupdate? Commented May 31, 2012 at 1:02
  • Yes, I'm just trying to pass the string to MakeRequest Commented May 31, 2012 at 1:06

1 Answer 1

1

You probably want to setup your tag to pass "this". I don't see where your raceupdate variable is declared, unless it's global... in which case you should show us what you're doing with that variable.

<select onchange='MakeRequest(this);'> 
    <option>Deathmateched</option>
    <?php
        dmList();
    ?>

If you did it that way, you'd have to change this function as such:

    function MakeRequest(element)
    {
    var linkInfo = "teleport.php?call=" + element.value;//create appropriate link depending on function parameters  
    var xmlHttp = getXMLHttp();

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

    xmlHttp.open("GET", linkInfo, true); //update page using link info variable created above
    xmlHttp.send(null);

}

And what are you trying to do here?

this.options[this.selectedIndex].value;

In your comments, it looks like you're saying you want to jump to an anchor tag? If so, then you would want to do something like

var anchorTag = document.getElementID("YOUR_ANCHOR_TAG_ID");
anchorTag.focus();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, Make the changes you suggested and everything works fine!

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.