0

is the jQuery function "change()" working in IE ?

I usually use it to detect changes in forms (select/unselect check boxes), and submit them automatically without having to click on submit button (which is hided).

i.e.

$("#views-exposed-form-Portfolio-page-1").change(function(){
        $("#views-exposed-form-Portfolio-page-1").submit();   
});

But in Ie it doesn't work. It seems I have to use "click" instead. thanks

Solution in IE:

if (navigator.appName == 'Microsoft Internet Explorer') {
    $(".option").click(function(){
        $("#loadingOverlay").css('display','block');

        if ($(this).children().is(':checked')) {
            $(this).children().attr('checked', '');
        } else {
            $(this).children().attr('checked', 'checked');
        }
        $("#views-exposed-form-Portfolio-page-1").submit();     
    }); 
}
Luke Woodward
  • 63,336
  • 16
  • 89
  • 104
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
  • 1
    Is that a `form` element or a `select`? Or which? – meder omuraliev Jun 13 '10 at 17:38
  • You may want to look at this: http://stackoverflow.com/questions/208471/getting-jquery-to-recognise-change-in-ie – James Black Jun 13 '10 at 17:38
  • It works perfectly in ie. Will u please show some other lines of code. – Mohit Jain Jun 13 '10 at 17:39
  • What version of jQuery are you using? The new(ish) 1.4 version makes event bubbling work almost perfectly across all the supported browsers. Prior to 1.4, it was not so perfect. – Pointy Jun 13 '10 at 18:10
  • @Pointy it is 1.2.7 (I cannot updgrade). Sorry I forgot to mention it. – aneuryzm Jun 13 '10 at 20:04
  • 2
    @Patrick - Then the answer is no, it doesn't work correctly due to the way IE does things, it was fully normalized in the jQuery 1.4.2 event re-write. – Nick Craver Jun 13 '10 at 20:07
  • ok. The problem with click is that it is tiggered without the form being updated.. maybe i should add a small delay ? – aneuryzm Jun 13 '10 at 20:24
  • mhm I'm using a small timeout, but still the checkbox is unchecked, I guess I have to toggle it by myself, probably with toggle jQuery command – aneuryzm Jun 13 '10 at 20:26
  • I'm trying now something like: $(".bef-select-all-none").click(function(){ // if not checked $(this).attr('checked', 'checked'); //else condition $(this).attr('checked', ''); //then... $("#views-exposed-form-Portfolio-page-1").submit(); }); – aneuryzm Jun 13 '10 at 20:36
  • Not sure this is the simplest approach. If it is easier, please let me know – aneuryzm Jun 13 '10 at 20:36
  • @Patrick - A `setTimeout(func, 0)` for checking the value doesn't work? Also what's the bottleneck against upgrading? just curious :) – Nick Craver Jun 13 '10 at 20:37
  • Drupal is the bottleneck... what's the point to set 0 ? i've set 1500 just to be sure it is triggered after the form is updated, but still nothing. – aneuryzm Jun 13 '10 at 20:42
  • @Patrick - The 0 is to let the bubble execute(0, 1500, doesn't matter) before moving on, you do the same on selects for IE to get the change before invoking a `form.submit()` Can you update the question with your code that *does* work? I'll honestly have to look at the best way to do this in 1.2.7 & IE, are you limited to durpal 6 atm? – Nick Craver Jun 13 '10 at 20:54
  • check this out. http://stackoverflow.com/questions/2875236/overriding-check-box-in-javascript-with-jquery – Gutzofter Jun 14 '10 at 01:20
  • @Nick: (1) I don't have a code that works in IE. It is working only in Firefox/Chrome/Safari. (2) ok. It still doesn't work with setTimeout(func,0). (3) What's Drupal "ATM" ? – aneuryzm Jun 14 '10 at 10:22
  • @Gutzofter: thanks for link. The point is that currently I'm checking the checkbox (even if it is already checked), just to see if it works in IE and it doesn't work (but I will definitely use the code you sent me after I solved this issue). – aneuryzm Jun 14 '10 at 10:26
  • See updated code for IE in website and updated question – aneuryzm Jun 14 '10 at 10:26
  • @Patrick - ATM == "at the moment", I mean for outside reasons you can't upgrade Durpal/jQuery to 1.4.2? – Nick Craver Jun 14 '10 at 10:31
  • The stable release of Drupal (6) supports jQuery 1.2.7. Waiting for Drupal 7. – aneuryzm Jun 14 '10 at 10:42
  • @everbody! Ok guys, I've finally solved. Who wants to be the answerer ? :) I've added the code to the question – aneuryzm Jun 14 '10 at 10:45

4 Answers4

0

It seems Jquery change function works in IE-7 now. 'Change' can be used with select(drop down), check box and radio buttons.

PSR
  • 1
0

In IE, change() doesn't work.. so I used the following code:

  if ($(this).children().is(':checked')) {
        $(this).children().attr('checked', '');
    } else {
        $(this).children().attr('checked', 'checked');
    }
    $("#views-exposed-form-Portfolio-page-1").submit();     
}); 
aneuryzm
  • 63,052
  • 100
  • 273
  • 488
0

See my answer here: IE not detecting jquery change method for checkbox

Community
  • 1
  • 1
kflorence
  • 2,187
  • 2
  • 16
  • 15
0

The change event will only be fired when the element loses focus (blurs). Click once again somewhere on the page so that your checkbox/radiobutton blurs, then you'll see that it get fired. In case of checkboxes and radiobuttons you'd indeed rather like to hook on click event. It also makes sense, clicking it will (un)check the checkbox/radiobutton anyway :)

This "problem" is not specifically related to IE.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555