Bug Tracker

Ticket #7406 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

Infinite loop in IE6 using option:selected

Reported by: phil.robare@… Owned by: phil.robare@…
Priority: undecided Milestone: 1.5
Component: unfiled Version: 1.4.3
Keywords: Cc:
Blocking: Blocked by:

Description

In IE 6 (Service Pack 3): [yeh, I'd like to drop support for it too]

In order to get a trigger to fire in both FireFox and IE when changing a drop-down style single select list I tried:

    jQuery(function() {
        $('.ErrorNameDropDown').change(setDefaultSeverity);
    });

This did not work in IE (it did in Firefox), to get it to work in both I had to code:

    jQuery(function() {
        $('.ErrorNameDropDown').bind(
            $.browser.msie ? 'propertychange': 'change',
            setDefaultSeverity);
    });

Finding the selected value was a problem too.

t=$('.ErrorNameDropDown option:selected').first().text();

The preceeding code went into an infinite loop in IE. The following code, which I think is equivalent, worked. Both versions worked in Firefox.

t=$('.ErrorNameDropDown').children(':selected').first().text();

Change History

comment:1 Changed 4 years ago by snover

  • Owner set to phil.robare@…
  • Status changed from new to pending

Please provide a reproducible test case on  jsFiddle.

comment:2 Changed 4 years ago by rwaldron

I'm just curious about this...

This code:

jQuery(function() {
 $('.ErrorNameDropDown').change(setDefaultSeverity);
});

Will listen for an event and handle it - not fire an event.

$('.ErrorNameDropDown option:selected').first().text();

:selected would only return 1 item, so why specify "first()"?

comment:3 Changed 4 years ago by rwaldron

works for me in IE 6,7,8

 http://jsfiddle.net/rwaldron/phUZk/2/

comment:4 Changed 4 years ago by phil.robare@…

  • Status changed from pending to new

I generated an example page that shows that the code goes into an infinite loop in IE. I tested it in both IE6 and IE7 with the same results. It works fine in jsFiddle and Firefox (Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12). The point of the bug is the broken javascript execution in IE has to be worked around. Here is the page:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
	Example for jQuery bug 7406
</title>
    <script type="text/javascript" src="jquery-1.4.3.min.js" ></script>
    <meta http-equiv="Content-Script-Type" content="text/javascript" /></head>
<body>
    <form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKLTE3MzI0MDE4Mg9kFgICAw9kFgICAQ8QZA8WBWYCAQICAgMCBBYFEAUKIC0tdW5zZXQtLQUBMGcQBRAxLjAgU3BpbGxlZCBNaWxrBQExZxAFETUuMCBCcm9rZW4gV2luZG93BQEyZxAFFjEwLjAgSW5jZW5zZWQgUmVsYXRpdmUFATNnEAUOMTUuMCBEZWFkIEJvZHkFATRnZGRkAjogtr8FLDoLwz+i36ihCJp/GBY=" />
</div>

    <div>
    <select name="ErrorName" id="ErrorName" class="ErrorNameDropDown">
	<option value="0"> --unset--</option>
	<option value="1">1.0 Spilled Milk</option>
	<option value="2">5.0 Broken Window</option>
	<option value="3">10.0 Incensed Relative</option>
	<option value="4">15.0 Dead Body</option>

</select>
    <select name="ErrorType" id="ErrorType" class="ErrorClassDropDown">
	<option selected="selected" value="0"> --unset--</option>
	<option value="1">Non-Critical</option>
	<option value="2">Critical</option>

</select>
    <input name="ErrorComment" type="text" id="ErrorComment" />
    </div>
    
<div>

	<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCgK6zKUJAt+s24MPAsCs24MPAsGs24MPAsKs24MPAsOs24MPAueWtKcEAviWtKcEAvmWtKcEAvCSr64KYMzeRUEF+CG8mPPM8bXH86ZxSX4=" />
</div></form>
        <script type="text/javascript">
    //<![CDATA[
    // When the value in error type is changed change the severity value to the
    // default severity for that error
    var old_t = 0;
    function setDefaultSeverity() {
        t=$('.ErrorNameDropDown option:selected').first().text();
        //t=$('.ErrorNameDropDown').children(':selected').first().text();
        if (t == old_t) return;
        old_t = t;
        if (t.match('^[0-9][0-9]')) { // critical errors start with two digits
            $('.ErrorClassDropDown').first().val(2);
        } else {
            $('.ErrorClassDropDown').first().val(1);
        }
        $("#ErrorComment").first().focus();
    }

    // on redirect jQuery is unassigned, IE reports an error
    if (jQuery)
    jQuery(function() {
        try {
        $('.ErrorNameDropDown').bind(
            $.browser.msie ? 'propertychange': 'change', setDefaultSeverity);
        } catch(e) {}
    });
    //]]>
    </script>

</body>
</html>

In response to rwaldron's questions: 1) The difference between binding to an event and handling an event is lost on me. I just got to where my code worked in both browsers. 2)I used .first() out of an excess of caution since a multi-select list might have more than one selected.

comment:5 Changed 4 years ago by rwaldron

  • Status changed from new to closed
  • Resolution set to invalid

Fixed. Please take a look at this:

 http://dl.dropbox.com/u/3531958/jquery/src/test-cases/7406.html

I made a few changes to your code, and its works perfectly on IE6 & 7. I commented the changes I made

I suspect that the issue was your RegExp

Last edited 4 years ago by rwaldron (previous) (diff)
Note: See TracTickets for help on using tickets.