0

I am having weird problem with IE9 in compatible mode(IE 7 standard) running Jquery(1.8.1) sometimes it runs the jQuery command other times it just does not take any action on the button when its clicked. The code is below for this simple page. I am using tiles to include resources like javascript , css.

When I click on the button sometimes it runs the logic other times it does not, I debugged using f12 I can see page has downloaded jQuery js for this to run. Please let me know what I have missed for this weird behavior.

<div style="margin: 50px 20px 50px 20px; text-align: center;">

<span>Do you want to submit this form ?</span>  

<form>
    <input id="yesButton" type="button" value="Yes"/> 
    <input id="noButton" type="button" value="No"/>
</form>

</div>

<script language="JavaScript">
    $(document).ready(function() {

        $('#yesButton').on('click', function() {
            $('#yesButton').attr('disabled', 'disabled');
            $('#noButton').attr('disabled', 'disabled');
            window.location = contextRoot + '/imging/stre/${caseId}/${documentTypeCode}';
        });

        $('#noButton').on('click', function() {
            $('#yesButton').attr('disabled', 'disabled');
            $('#noButton').attr('disabled', 'disabled');
            $.ajax({
                url: contextRoot + '/imging/clr/${Id}/${documentTypeCode}',
                type: 'POST',
                dataType: 'text'
            });
            window.close();
        });

    });
</script>
pk2
  • 15
  • 5
  • 1
    I'm surprised that's working consistently in ANY browser. access/modify the disabled property with the .prop method, not .attr – Kevin B Apr 10 '13 at 15:09
  • if you put an `alert()` statement in the event handlers does it always show? – BNL Apr 10 '13 at 15:10
  • This is from jQuery 1.6, but still applies here: http://stackoverflow.com/questions/5874652/prop-vs-attr – Kevin B Apr 10 '13 at 15:11
  • Do you get any errors in your browser's console at any point? – Anthony Grist Apr 10 '13 at 15:11
  • @KevinB No objections that they should be using `.prop()`, but I think jQuery 1.8 would hold their hand and make sure using `.attr()` still disabled the element. – Anthony Grist Apr 10 '13 at 15:13
  • I get alert sometimes , not alwys and buttons does not grey out when they are clicked – pk2 Apr 10 '13 at 15:13
  • @AnthonyGrist Agreed, this won't be an issue in 1.7-1.8, only in 1.9. The symptoms do point toward 1.9 though. in 1.9, the first call to it will work, but subsequent calls to it won't have any effect. All speculation of course. @pk2 Where is `contextRoot` defined? – Kevin B Apr 10 '13 at 15:16
  • stop using the language attribute on your script tags. use `type="text/javascript"` or no attribute at all. Also, as mentioned above, do not use `.attr()` for things like `disabled`--use `.prop()` with a boolean value. – JAAulde Apr 10 '13 at 15:16
  • @Kevin B contextRoot is defined in another jsp file , I am using apache tiles to layout page contents – pk2 Apr 12 '13 at 18:34

0 Answers0