Solved

Using   window.onLoad = or   window.onLoad +=

Posted on 2013-12-18
2
277 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39726398
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
ID: 39726759
Excellent - thanks!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

710 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