Avatar of rcl58
rcl58
 asked on

Intermittent jQuery in IE 11 Only

I’m trying to change a button color in an iFrame bases on the drop down list. My code works every time in Chrome but in IE it works about 45% of the time. It fails on loading. If it works on load it keeps working. If it fails on load it never works. Note, this is a DNN site.

Non-repeatable bugs drive me crazy. Any ideas?

Thanks!

    function buttonColor()
        {
            var color
            switch ($(this).val())
            {
                case "Orange": color = "#FF8429"; break;
                case "Green": color = "#00C354"; break;

            };

            var btn = $(this).closest("td").siblings("td").find(".btnPayPal");
            btn.css("background-color", color);
            btn.css("border", "1px solid " + color);

        }; // END buttonColor

    </script>
    <script>
        $(window).ready(function ()
        {
            $(".iFProductOne").load(function () { $(".iFProductOne").contents().find(".ddlPayPal").on("change", buttonColor) });
            $(".iFProductTwo").load(function () { $(".iFProductTwo").contents().find(".ddlPayPal").on("change", buttonColor) });
            console.log("Win Ready");
        }); 
    </script>

Open in new window


IFRAME LOADED:

Form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="XXX">
<table class="ppTable">
    <tr>
        <td>
            <select name="os0"  class="ddlPayPal">
                <option value="Orange">Orange </option>
                <option value="Green">Green </option>
            </select>
        </td>
        <td>
            <input class="btnPayPal" type="submit" border="0" name="submit" value="Add to Cart" style="color: white;
                background-color: gray; border: 1px solid #FF8429" />
        </td>
    </tr>
</table>
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif"
    width="1" height="1">
</form>

Open in new window

ASP.NETjQuery

Avatar of undefined
Last Comment
rcl58

8/22/2022 - Mon
leakim971

Did you really put :  $(window).ready(function ()
instead :  $(window).load(function ()
rcl58

ASKER
I have the code in $(window).ready because in reality I have six iframes on the page and it was binding to maybe two sporadically which lead me to believe that all the iframes were not loaded yet. I tried it in $(document).ready, $(window).load and just in <script>. I’ve gotten closest with in $(window).ready.

I have also added a trigger to to compensate for the widow being completed.

$(".iFProductOne").load(function () { $(".iFProductOne").contents().find(".ddlPayPal").on("change", buttonColor) });
$(".iFProductOne").load(function () { $(".iFProductOne").contents().find(".ddlPayPal").trigger("change") });

Open in new window

ASKER CERTIFIED SOLUTION
leakim971

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
rcl58

ASKER
I have not solved this problem but have to move on and will re-examine later. TX
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23