Solved

Using   window.onLoad = or   window.onLoad +=

Posted on 2013-12-18
2
269 Views
Last Modified: 2013-12-18
I'm trying to avoid ViewState Mac errors and one of the solutions is to disable the form and re-enable it when the page loads to prevent premature submissions of the form before it has finished loading (see here for a good discussion of the options - http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx)

To enable the form again the above page has this:

  function enableForm() { 
      document.getElementById("form").disabled = false; 
  } 

  window.onLoad = enableForm();

Open in new window


I wasn't sure if this would replace any existing window.onLoad event handlers, and if you are supposed to enter

  window.onLoad += enableForm();

and if you are supposed to do this whether it would put "enableForm()" as the first function called after onLoad?
0
Comment
Question by:purplesoup
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
See by yourself :

http://jsfiddle.net/yuDbL/
http://jsfiddle.net/yuDbL/1/

Your should have IE9+ to see the alerts on the second one else you need to use attachEvent instead addEventListener : http://msdn.microsoft.com/en-us/library/ie/ms536343(v=vs.85).aspx

So as you can see he order is very important. If you want your code run first, you must put it in the first place but if you use window.onload it MAY BE overwritten by the others scripts that come after your script

I would suggest you to use addEventListener and put your script in the first position in the HEAD section
0
 

Author Closing Comment

by:purplesoup
Comment Utility
Excellent - thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now