javascript - Is null after getElementById? -


There is a very easy error here, I'm sure, but basically I have an ID

formID Calling this way:
  & lt; Script type = "text / javascript" & gt; Function redvalidate () {var form = document.getElementById ("formID") var fields = form.getElementsByClassName ("validate"),   

and I'm getting the error:

UPDATE

> Ok so basically I have two onsites for a form, which obviously works does not. So what I'm doing is calling this function from someone else ...

This type of tag is:

    

And Heres RememberFormFields:

  & lt; Script type = "text / javascript" & gt; Function RememberFormFields (form, list) {redvalidate () ... etc ... rememberformfields function ... et.c ..    

anywhere on your page, you just do not need to load your javascript after the DOM is ready. Attempting to get an ID from an element that has not yet been implemented on the DOM and thus JavaScript is viewed as NULL

There are many ways to do this: You can put all your JS near the & lt; / body & gt; tag, you can add all your JS to the & lt; head & gt;

This is one of the reasons that JQuery is very easy because you can wrap your code in the $ .ready (function () {}) ; Block Any DOM-handwriting scripts will always work because they wait until the DOM creates a fire. In this modern browser "DOMContentLoaded" Iwen Finds it by looking for T, and IE has a doScrollCheck () function that tries to scroll the body as much as possible - if it is scroll, then it knows that it Good go away You can easily repeat this practice if you do not want to load JQuery for this.

JOM DOM Ready Check:

  if (document.addEventListener) {DOMContentLoaded = function () {document.removeEventListener ("DOMContentLoaded", DOMContentLoaded, false); JQuery.ready (); }; } And if (document.attachEvent) {DOMContentLoaded = function () {// Make sure the body is present, at least, in case the IE bit a little bit cheerful (Ticket # 5443). If (document.readyState === "full") {document.detachEvent ("onreadystatechange", DOMContentLoaded); JQuery.ready (); }}; } // DOM Ready Check for Internet Explorer Function doScrollCheck () {if (jQuery.isReady) {return; } Try {// If IE is used, then use the trick by Diego Perini http: // http://javascript.nwbox.com/IEContentLoaded/ document.documentElement.doScroll ("left"); } Hold (e) {setTimeout (doScrollCheck, 1); Return; } // and implement any waiting tasks jQuery.ready (); } Returns jQuery; }) ();    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -