1

I use an iframe on my page, which consists of a form with input elements. Every input element has an onblur() event, which validates the input.

When I open the page in IE 8 with a freshly cleared cache it produces a javascript error like this.

document.getElementById(...)' is Null or not an Object

However, when I inspect the form it is loaded completely and the I'm trying to access is rendered. Furthermore when i reload the whole page I don't get any errors anymore. Also when I load the content of the iframe on its own I also don't get errors.

Firefox and Chrome dont throw errors at all.

In short, the Javascript errors I get only occur in IE and only when I use an iframe to display the form (which is mandatory) and only when the page is loaded for the first time.

Any ideas on how I can fix this?

I hope its not too confusing to read.

Edit:

document.getElementById("vHint_"+fieldName).innerHTML=data;

FieldName is the id of the input field. Data is the return value of the validation. In this case data is an image tag. After every input field is a span Tag with the id "vHint_"+fieldName.

The event is attached like this:

<input id="Jahr" class="input" type="text" onblur="validDate(this,'Jahr','_beginn')" maxlength="4" style="width:32px" value="" name="Jahr">
14
  • So, onload you do a loop by getElementById() and attach onblur, and here is where the error occurs? Commented Feb 13, 2014 at 8:40
  • The onblur is fired after the user inputs data in the inputs element. Then the input is validated and then getElementById() is used to display wether the inputs were correct. Commented Feb 13, 2014 at 8:45
  • can you add your code your using for getElementId() where the error is coming Commented Feb 13, 2014 at 8:47
  • Yes, but where and when does the error manifest itself? On load, on first blur, etc. Where does the script reside? In iframe or mother DOM. Is it attached in header, inline or external script? How and where? By what does the error trigger? – If you are able to make a minimal example on e.g. jsfiddle that would most likely be rather helpful. Commented Feb 13, 2014 at 8:49
  • The script is located in the head section of the iframes content. The event is triggered by the user filling in data. So the error occurs on first onblur() event Commented Feb 13, 2014 at 8:54

1 Answer 1

1

First of all thank you for your effort. The example user13500 provided worked like a charm. And it made me dig deeper.

And i found the solution.

All input fields are created with a self made ASP Framework, which puts them all in the Session. The onblur() event of the input field within the iframe triggers an AJAX Request to an ASP file passing the name of the input field as a request parameter. The ASP file now tries to find the field in the Session and retrieve its value to validate the input. After that the result is posted back to the javascript file, which then uses document.getElementById("vHint_"+fieldName).innerHTML=data; to post the result back in the page.

This normally works without erros. But, since the application is run in an iframe and the domains of the surrounding page and the application in the iframe are different, IE rejects the Session of the iframe. Thus the result of the ASP validation is empty, because it couldn't find the field in the Session.

Having figured that out the only thing that has to be done is to add this line of code in the application:

Response.AddHeader "P3P", "CP=""CAO PSA OUR"""

This way IE doesn't reject the Session of the application anymore. Maybe this can be useful for others too.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.