Need Help with Javascript code - length is null or not an object in read mode

I have a form that is used on the web. The form contains an iframe that is used to populate my keyword field. Here’s the code on the iframe:

This works great when I create a new document and everything submits just fine. The problem is when I go back into the document to read it. The iframe is loading and I get an error at the 5th line, oldstore.length is null or not an object. I’m not sure but I think this is because when I’m reading the document, the field is just a value, and not a dialog list anymore??? Then when I put it into edit, I don’t get the error.

Any ideas on how I can fix this? I’m pretty new to javascript and I’m not having any luck coming up with a fix. Help!!

Karen

Subject: Need Help with Javascript code - length is null or not an object in read mode

Your diagnosis is correct – there is no field in play in read mode, it’s just another blob of text on the web page. If you can’t selectively load your JavaScript (using @If(@IsDocBeingEdited) in the HTML head with JS libraries or file resources), then you’ll need to inject some “does it exist” code to stop the processing:

if (document.forms[0].elements[‘Store’]) {

//go ahead and play

}

Oh, and do yourself a big favour and stop using document.all – unless you really, really need to support Internet Explorer 4. You can write cross-browser code for IE5+, Netscape 6+, Mozilla, Firefox, Safari, Konqueror, Opera 6+ and everything else under the sun by using collections for elements identified by name only:

document.images[‘imageName’]

document.forms[‘indexOrName’].elements[‘fieldOrButtonName’]

or, for elements identified by ID, by using:

document.getElementByID(‘elementUniqueIdentifier’)

or iterate through an element collection gotten by getElementsByTagName():

document.getElementById(‘secondTable’).getElementsByTagName(‘tr’)

All of those will run just as well in IE5+ as document.all, and you’ll never have to re-code to make it work in any other current browser.

Subject: RE: Need Help with Javascript code - length is null or not an object in read mode

Thank you very much! So far so good, however now I’m running into something else. When I put the document into edit mode, I’m losing the value I already have selected in my keyword field. How can I get it to retain the selected value? I’m assuming my code is running which is clearing out the value. How can I tell it to keep the value if there is one already there?

Any advice is greatly appreciated. I’m new at this but I’m slowly learning! Thanks!

Subject: RE: Need Help with Javascript code - length is null or not an object in read mode

Nevermind! It didn’t have anything to do with the javascript. It had to do with the default field values. Not sure why it was removing my values - but it’s working now so at this point I don’t really care!

Thanks for you help!