I’m fairly new to JavaScript and always find myself struggling with IE problems. The following code works in FireFox, but gives the old “Object Not Found” error in IE:
[code=php]<script type=”application/javascript”>
function disableAddress (inputElement, setting)
{
var formElements = inputElement.form.elements;
formElements[“address_ok”].disabled=setting;
formElements[“address_change”].disabled=setting;
formElements[“street”].disabled=setting;
formElements[“city”].disabled=setting;
formElements[“state”].disabled=setting;
formElements[“zip”].disabled=setting;
}
</script>
It’s called when you click a radio button:
[code=html]<input type=”radio” name=”election” value=”Pay-Out” onclick=”disableAddress(this, false);” />
or
<input type=”radio” name=”election” value=”Reinvest” onclick=”disableAddress(this, true);” />
Clicking any of the radio buttons, regardless of the parameters in them, gives the error.
As far as I can tell, it’s because IE isn’t finding the script, which is defined a few lines above the form containing the radio. If I paste the code directly into the onclick event in the radio’s input tag, it works. However, I keep having the same problem on other pages I am building and I want to know the right way to get this to work.
Other notes – the script block is defined in the body of the page, not the head – the site is complex and driven by lots (and lots) of PHP, so it’s not especially practical to stick it in the head. It should work anyway, shouldn’t it? I have also tried to include such scripts in external files with a script scr= type tag and that has the same results – FF good, IE bad.
Thanks,
Frank