Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Using   window.onLoad = or   window.onLoad +=

Posted on 2013-12-18
2
Medium Priority
?
281 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

719 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