I\'ve got a page with a variable number of elements (which explains why I\'m using event delegation here). When the user changes the selected opt
Idea that might help:
$(document).ready(function() {
$('#container select[name="mySelectName"]').change(function(e) {
var s = $(e.target);
if (s.val()=='1') //hide/show something;
});
});
If you are using AJAX, try live() function:
$(document).ready(function() {
$('#container select[name="mySelectName"]').live('change', function(e) {
var s = $(e.target);
if (s.val()=='1') //hide/show something;
});
});
If I recall correctly you will need to call blur() to have jQuery invoke change() on IE machines. Try something like:
$("select[name=mySelectName]").click(function() {
$(this).blur();
});
I'm simply building upon the example set by "Crescent Flesh" for a cross-platform solution that will survive even if loading this SELECT inside #container via an AJAX call.
$('#container').bind($.browser.msie ? 'click' : 'change', function(event) {
if ((event.type == 'click') || (event.type == 'change')) {
if (event.target.toString().indexOf('Select') != -1) {
var sWhich = $('#container SELECT').val();
handleSelectionChange(sWhich);
}
}
});
Now you simply build the handleSelectionChange() function, renaming it whatever you want.
using jquery 1.4.4 (and i think 1.4.3) seems to be all good now.... the change event works consistently in my limited testing.
:D:D Wow, I was finding solution... Why think so complicated?
Simply:
<select onchange="doAction">
Add this lines to your page head, Sit back and relax! :)
$(document).ready(function(){$('select').bind('onChange',function(){$(this).blur()});});