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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble with getElementById (Cross-browser)

    Firstly the scenario:

    Two checkboxes (linethrough, underline), that when clicked, update an element specified by tagname and tagid, using a function I created (which works), changePropByTagId (A variation on getElementsById) .

    Secondly, the code:
    Code:
    function checkcheckbox(tagname,tagid,underline,linethrough) 
    {
    var style = "";
    if (document.getElementById(underline).checked == true) { style += ' underline'; }
    if (document.getElementById(linethrough).checked == true) { style += ' line-through'; }
    if (style == "") { textDecoration = 'none'; } else { textDecoration = style; }
    changePropsByTagId(tagname,tagid,'style.textDecoration',textDecoration);
    }
    Thirdly, what is supposed to happen?
    Checks both checkboxes, if one is checked, appends underline and/or line-through to the var 'style' and then calls my property to change the element text-decoration property with a value of 'textDecoration'.

    Fourthly, what is actually happening?
    Firefox and Opera 8, working perfectly.
    IE, choosing a single checkbox works fine, but upon selecting BOTH checkboxes, a 'Invalid Argument' error occurs.

    Hope I've detailed this enough!
    Any suggestions?
    Many thanks,
    Rob of MyGen.

  • #2
    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
    I guess that the problem is about the dynamic CSS values seting:

    IE doesn't like the empty spaces in front of the compunded values, so that try remove it

    { style += 'underline';
    instead of
    { style += ' underline';
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Aug 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Absolutely brilliant, worked a charm.
    At first, with both checkboxes ticked, the value of style was coming to "line-throughunderline" which is obviously invalid css, so i changed it to 'line-through ' <- notice the space, and IE liked that better.

    Once again, many many thanks


  •  

    Posting Permissions

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