Sean Bone
Sean Bone

Reputation: 3546

Detecting when the user chooses an option from a dropdown

I have a classic HTML select box:

Show:
<select name="show" id="showThreads">
   <option value="all" selected="selected">All</option>
   <option value="new">Only unread</option>
</select>

Now, I need JavaScript to make an Ajax request when the user changes the selection in the box (without jQuery). I have tried:

Is there a way of doing this that will work on all browsers/devices? Thanks!

Upvotes: 0

Views: 61

Answers (3)

Subhajit
Subhajit

Reputation: 1987

function yourAjaxCall(something) {

}

<select name="choice1" size="1" onchange="yourAjaxCall(this);">
    <option value="one">first</option>
    <option value="two">second</option>
    <option value="three">third</option>
</select>

Upvotes: 0

Esailija
Esailija

Reputation: 140236

Try the "change" event.

document.getElementById("showThreads").onchange = function() {

};

Upvotes: 3

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324780

Listen for onChange on the <select> tag.

Upvotes: 3

Related Questions