views:

64

answers:

4
$('#XynBp0').find('input').each(function(){
    if ($(this).attr('value') == 'Cancel'){
        $(this).trigger('click');
    }
});

doesn't work in IE7

+1  A: 

it's strange but try to create a custom event

$('#XynBp0 input').bind('custom',function(){
 //code
})


$('#XynBp0').find('input').each(function(){
    if ($(this).attr('value') == 'Cancel'){
        $(this).trigger('custom');
    }
});

Does this work?

Mouhannad
No, but thank you. I tried this and put an alert in the custom function but nothing alerted. Very strange that this works in any browser if it fails in IE7
syn4k
maybe if you share the rest of the code we can give a better answer!
Mouhannad
+1  A: 

$.click() (or $.trigger('click')) doesn't simulate a mouse click, it fires off any onclick events bound to that element. If you haven't assigned an onclick event to that input you're searching for, nothing will happen.

It sounds like you're trying to submit the form with an <input type="submit" value="Cancel"> kind of submit button. If that's the case, you may have to use $(yourform).submit() to submit the form, in combination with some handling of the data sent to the server to simulate clicking the Cancel button.

Jason S.
Thanks Jason but this works perfectly fine in Firefox and Chrome
syn4k
A: 

Is it wrapped in a dom ready event? Might help if you provide more code.

$(function () {

    $('#XynBp0').find('input').each(function () {
        if ($(this).attr('value') == 'Cancel') {
            $(this).trigger('click');
        }
    });

});
fehays
A: 

Your code snippit doesn't make any sense, you are clicking inputs if they are canceled?

Here's some things to clean up in your code

$('input','#XynBp0').each(function () {
  var $this = $(this);
  if ( this.value === 'Cancel' ) { //Don't need jQuery here
    $this.trigger('click');  //Probably don't need it here either
  }
});

What does click even do? If you are trying to submit a form, use form.submit();

Drew
Again, this works as it should in ALL other browsers. It makes perfect sense. The code fires the click event on that particular input.
syn4k
Can you post the HTML and the rest of the code? I can get this working in all browsers, if I had an idea of what you are trying to do.
Drew