Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    3
    Thanked 0 Times in 0 Posts

    setting background color in Javascript doesn't make this color appear under IE7

    Hi,

    I'm faced with a problem trying to set background color under IE7. I have the following Javascript:

    Code:
    function showLayer793BKColor(id)
    {
      var txtObj = document.all(id);
      if (txtObj.style.display == 'none')
      {
           txtObj.style.display = ''
           txtObj.style.backgroundColor 	= 'grey';
      }
    }
    
    function hideLayer793BKColor(id)
    {
      var txtObj = document.all(id);
      if ( txtObj.style.backgroundColor == 'grey' )
        txtObj.style.display = 'none';
    }
    These functions are used to show or hide div blocks.
    These blocks are, for example, specified in the following way:

    Code:
    <div id="l_gct5tekst" style="display:none">
    	<b>GCT 5. Eerste verkenning problematiek</b>
    and, for example,

    Code:
    <div id="l_Keuze" style="display:none">
    	<br/>
    	<b>GCT 5</b>
    	<br/>
    </div>
    The whole configuration works smoothly when using IE8. However, when using IE7 I get an error msg like "Invalid value for property". When I use the Color propert iso the BackgroundColor property I get no error anymore but of course I don't have a background color anymore then.

    In what way can I specify the use of a background color under IE7 ? Or is just not possible in one way or the other.

    Furthermore, what more differences between JS under IE7 and IE8 do I have to take into account ?

    Do I also have to rewrite my div block in some way (using some attribs ?) to cope with IE7 ?

    Thanks in advance,

    Diederick van Elst

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    First of all you should switch from document.all() to document.getElementById() which is the standards compliant way of addressing elements by their id property.

    Second: Can you show us where and how you call the specified functions?

  • Users who have thanked devnull69 for this post:

    d_elst (07-21-2011)

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    On the other hand the id token must not start with a digit. See also the W3C Recommendation:

    "ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")."
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    It's a lower case L and not a 1 (one)

  • Users who have thanked devnull69 for this post:

    d_elst (07-21-2011)

  • #5
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    use getElementById()
    Code:
    var txtObj = document.getElementById(id);
    document.all is an old, IE only, reference. Even so, you use it incorrectly:
    Code:
    var txtObj = document.all(id);
    document.all[] needs square bracket notation, not rounded squares. This is the reason for IE7 throws that error.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    d_elst (07-21-2011)

  • #6
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    2
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Thanks for the comments given.

    I'm making adjustments in very old legacy code (ca. 8 years old). I understand now that one shouldn't use document.all[] anymore since the introduction of IE5.

    However, I have to draw your attention again to my original question:

    "In what way can I specify the use of a background color under IE7 ? Or is just not possible in one way or the other ?"

    Like I said before, the code runs smoothly under IE8. This is regardless of document.all() issues.
    The browser clearly indicates that the lines of code where the errors originate are the ones where the backgroundColor property is used.

    For completeness I have posted the complete xsl file. I call the function showLayer793BKColor() by writing

    Code:
    function zet_aan_uit_5()
    {
     if(	(document.invoermodel.Punt1Keuze.checked)
    	|| 	(document.invoermodel.Punt2Keuze.checked)
    	|| 	(document.invoermodel.Punt3Keuze.checked)
    	|| 	(document.invoermodel.Punt4Keuze.checked)
    	|| 	(document.invoermodel.Punt5Keuze.checked)
    	|| 	(document.invoermodel.Punt6Keuze.checked)
     )
     {
    	showLayer793BKColor('l_Keuze');
    	if(	(document.invoermodel.Punt1Keuze.checked) )
    	{
    		showLayer793BKColor('l_Punt1Keuze');
    	}
    ...
    ...
    In which 'l_Keuze' and 'l_Punt1Keuze' are id's of div blocks.

    I would have liked to post the complete code but text length restrictions won't let me..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •