View Full Version : Trouble with getElementById (Cross-browser)

08-17-2005, 11:19 PM
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:

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; }

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.

08-18-2005, 11:07 AM
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';

08-18-2005, 07:46 PM
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 :)