I've run into an issue where a piece of Javascript I have written will only work in a webkit based browser - I have tested and passed with Chrome and Safari. I have failed with Firefox, IE and Opera.
function rebar(checked)
{
var element = document.getElementById('fdn-strip-rebar-weight');
if(checked=="on")
{
element.className = "";
}
else
{
element.className = "hidden";
}
return true;
}
All the above code does is cause a text box to appear when a checkbox is ticked and disappear when unticked. The first part works in all browsers, however when unticking the box, in anything but webkit, the field fails to disappear. Any tips or suggestions?
Last edited by timWebUK on Fri Aug 27, 2010 10:41 am, edited 1 time in total.
The most obvious suggestion is to set a breakpoint in firebug and see what are the values for parameter and local variables. Also check if element.className is, in fact, set to 'hidden' before you're leaving the function - if it is, then there's probably a problem somewhere else (like in your css).
I can't see how it would work in some browsers and not others, Chrome is usually pretty good with debugging Javascript. I've checked my CSS and can't see anything wrong with it. I'm just declaring a global class called:
It looks like Firefox doesn't even know the element exists. Do a console.dir() of the element right after you select it to see if both browsers at least agree to that point.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
HTMLInputElement provides a drop down list of all the possible attributes and settings and styles for it.
Firebug:
>>> console.dir(blnBasement)
ReferenceError: blnBasement is not defined { message="blnBasement is not defined", more...}
Firebug saying the same again. Can't understand why it wouldn't recognise it. The tick box is within the <form> tags, my code is completely compliant to the latest Strict XHTML standards.
Done that, behaves a bit better in the console now. Modified my Javascript to look for 'true' instead of 'on' as well. But Firefox doesn't work at all now, it doesn't even add the value to the text field.
EDIT:
False alarm, after trying it in all the other browsers and it worked, I realised Firefox had cached the page, after a forced refresh it is working. Thanks guys.