Solved

Using   window.onLoad = or   window.onLoad +=

Posted on 2013-12-18
2
274 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Finding Events logs for IIS website that restarts 2 14
ASP.NET Content Page 3 25
Need syntax help building hyperlink 2 20
linq, c# 8 22
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

791 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