Reputation: 9621
I have this code:
<select>
<option onChange="filterProducts(this);">Select ...</option>
<option onChange="filterProducts(this);">Samsung</option>
<option onChange="filterProducts(this);">LG</option>
<option onChange="filterProducts(this);">Sony</option>
<option onChange="filterProducts(this);">Philips</option>
</select>
Which should fire a js method but it simply does not fire:
function filterProducts(firedByControl){
alert(fired);
}
For this button, calling the same js method, all works nice:
<button type="button" class="btn" onclick="filterProducts(this)" value="LCD">LCD</button>
Can you please tell me where I am wrong?
Upvotes: 1
Views: 410
Reputation: 56432
You need to place the onchange attribute on the select
, not on the option
.
By the way, you should probably do something like that using JQuery :
$("select").onChange(filterProducts);
Upvotes: 1
Reputation: 139921
I believe that onchange
should be an attribute of the <select>
element, not each <option>
.
Upvotes: 1
Reputation: 79830
Move the onchange
to the select like below,
<select onchange="filterProducts">
Upvotes: 1
Reputation: 7593
You need to put the onchange call on the element.
<select onChange="filterProducts(...);">
<option>Select ...</option>
<option>Samsung</option>
<option>LG</option>
<option>Sony</option>
<option>Philips</option>
</select>
Upvotes: 3