mistily
mistily

Reputation: 63

onchange does not work

I have this code

<select id="priority" onchange="myfunction(10);">
    <option>0</option>
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
</select>

and what i don't understand that it does not trigger the event on the change of the select tag. Why is that?

Upvotes: 0

Views: 139

Answers (2)

Md Ashaduzzaman
Md Ashaduzzaman

Reputation: 4038

If you want to stick to your own code, then you have to change the handler on jsFiddle as mentioned by @Pointy. But if you want it to be done in another way, then try it as below.

javaScript :

priority.onchange = function myfunction()
{
    alert("On change worked");
}

jQuery :

$("#priority").change({id : 10}, function(event){
    alert(event.data.id);
});

Demo

Upvotes: 1

Pointy
Pointy

Reputation: 413682

You've told jsfiddle to put your JavaScript code inside a "load" handler. Thus, your function isn't global and won't be found when the element changes.

Change the pulldown that currently says "onLoad" to either "no wrap (head)" or "no wrap (body)".

Upvotes: 1

Related Questions