Solved

Code does not work with IE

Posted on 2012-03-15
3
269 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now