Slow running script in IE8 So I've got this &quot;nice&quot; Drupal 7 site and there is a node with a large (70is) fields that the user fills in. There is a script that hides and shows certain questions depending on the previous answer. It works fine in IE9, FF, Chrome and Safari but in IE8 it gives this error:

A script on this page is causing Internet Explorer to run slowly. If it continues to run, your computer might become unresponsive.
Stop running script? YES/NO

There are only around 10 lines of my code being run, the rest is written out by Drupal. Is there a way to split up the script or speed it up? Or should I avoid using Drupal to write javascript and custom code it?
EXAMPLE
In the node/add I have code like this:
$form['group_section_one']['field_permit_number']['#states'] = array(
        'visible' =&gt; array(
            ':input[name=&quot;field_do_you_have_a_permit[und]&quot;]' =&gt; array('value' =&gt; '1'),
        )
    );

To show the &quot;permit number&quot; field if they answer Yes to &quot;Do you have a permit?&quot;. I do a similar thing for another 60 fields sometimes they depend on up to 4 field values.
That then writes out javascript which equates to around 100 lines all up. I wouldn't have thought that would freeze up the browser though...
The tough thing here is that IE 8 is notoriously poor in terms of JS performance (compared to recent versions of FireFox, Chrome, Safari and even IE), and there's not a whole lot you can do to fix that.

However, in this case, I would consider one of two options:


Try to use different (faster) selectors besides :input[name="field_name[und]"] with Drupal's AJAX form states. If fields have IDs (they should, if the form is generated by Drupal), use the id instead, like field_name.
(If the above doesn't work) Try coding the visibility yourself (forgoing Drupal's FAPI #states system). You can optimize selectors and overall memory usage and performance by hand-tuning the jQuery or JavaScript yourself.


I'm guessing following #1 could fix your problem, though. For more reading on jQuery selector performance, see:


Your jQuery: Now with 67% Less Suck
jQuery Selector Performance Testing


However, for a form as large as yours, even hand tuning the JS might not be enough to get rid of that warning in IE. I have one form on a site I work on that always pops up that warning, and we sadly just have to tell users to ignore it. It's annoying, but it's acceptable to tell users to dismiss the warning in this particular case.