Solved

Code does not work with IE

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

910 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

25 Experts available now in Live!

Get 1:1 Help Now