Skip to content Skip to sidebar Skip to footer

Pass Function Parameters From Onchange To Javascript Function

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 HTM

Solution 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.

Solution 2:

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.

Solution 3:

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

Post a Comment for "Pass Function Parameters From Onchange To Javascript Function"