Solved

Code does not work with IE

Posted on 2012-03-15
3
275 Views
Last Modified: 2012-06-27
Hi Experts,

Please look at the code below. When a user clicks one of the two fields the field is highlighted with a bold border. It works with Firefox and Chrome but not IE.

<html>
<head>
    <title></title>
    <link href="default.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">

        function highlightOffer(offerNumber) {

            switch (offerNumber) {
                case 1:
                    document.getElementById('offer1').setAttribute("style", "border-width: 5; border-spacing: 1; border-style: solid; border-color: Green;");
                    document.getElementById('offer2').setAttribute("style", "border-width: 5; border-spacing: 1; border-style: none; border-color: Green;");
                    break;
                case 2:
                    document.getElementById('offer1').setAttribute("style", "border-width: 5; border-spacing: 1; border-style: none; border-color: Green;");
                    document.getElementById('offer2').setAttribute("style", "border-width: 5; border-spacing: 1; border-style: solid; border-color: Green;");
                    break;
 
            }

        }

    </script>
</head>
<body>
    <center>
        <table width="1000">
            <tr>
                <td width="25%">
                    <table onclick="javascript:highlightOffer(1);" id="offer1" style="border-width: 5;
                        border-spacing: 1; border-style: none; border-color: Green;" width="100%">
                        <tr>
                            <td align="center" style="border-width: 1; border-style: solid; border-color: Green;"
                                bgcolor="White">
                                <br />
                                <h2>
                                    1 Title</h2>
                                <br />
                            </td>
                        </tr>
                    </table>
                </td>
                <td width="25%">
                    <table onclick="javascript:highlightOffer(2);" id="offer2" style="border-width: 5;
                        border-spacing: 1; border-style: solid; border-color: Green;" width="100%">
                        <tr>
                            <td align="center" style="border-width: 1; border-style: solid; border-color: Green;"
                                bgcolor="White">
                                <br />
                                <h2>
                                    2 Title</h2>
                                <br />
                            </td>
                        </tr>
                    </table>
                </td>      
            </tr>
        </table>
        <br />
    </center>
</body>
</html>
0
Comment
Question by:DColin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 37724036
try cleaning up the code a bit. Rather than assigning the attributes one by one using JavaScript, assign a different class to the element
0
 
LVL 30

Expert Comment

by:IanTh
ID: 37724067
/mcrosoft are going to silently updating ie without warning so in future for code to work in ie it needs to be exeptionally clean so you dont have to fix it for each new version
I would suggest getting into html5 as thats what is going to work with ie I think
0
 
LVL 13

Accepted Solution

by:
F Igor earned 500 total points
ID: 37724092
setAttribute is a lot buggy in IE for style elements and events,
you should prefer to assign a class attribute:


CSS Code
.non_highlight {
border-width: 1; border-spacing: 1; border-style: none; border-color: Green;
}

.highlight {
border-width: 5; border-spacing: 1; border-style: none; border-color: Green;
}

Open in new window


HTML code (fix tables)
<table onclick="javascript:highlightOffer(1);" id="offer1" class="non_highlight" width="100%">

Open in new window


Javascript code (change attribute class instead of changing style)
document.getElementById('offer1').setAttribute("class", "highlight");
//or
document.getElementById('offer1').className="highlight";

Open in new window

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question