Solved

JavaScript error

Posted on 2016-11-16
1
80 Views
Last Modified: 2016-11-22
I have an old web site with the following script in aspx page. When I load the Solution into Visual Studio, it complains that the syntax function window.onload() is an error. How do I fix it and hat has changed?

function window.onload() { 
			    var role = new String("<% =NMUser.Access%>");
			    var login = new String("<%=NMUser.LoggedFor %>");
			    document.login = login;
			    document.role = role;
				var tblMain = document.getElementById("tblMain");
				tblMain.greenBarIt = showGreenBar;
				tblMain.clear = clearTable;
				tblMain.greenBarIt();//showGreenBar();
				tblMain.onmouseout=tblMain_onmouseOut;
				tblMain.AddMailTo= addMailTo;
				tblMain.AddMailTo();
				document.Form1.txtPwd.onkeydown = txtPwd_onkeydown;
				var cboPage = document.getElementById("cboPage");
				cboPage.onchange = cboPage_onchange;
				var txtLookup = document.getElementById("txtLookup");
				txtLookup.tbl = tblMain;
				txtLookup.onkeyup = txtLookupKeyUp;
				txtLookup.onkeydown = txtLookupKeyDown;
				var btnSearch = document.getElementById("btnSearch");
				var anc_createNewMatter = document.getElementById("anc_createNewMatter");
				anc_createNewMatter.onclick = anc_createNewMatter_Click;
				btnSearch.txt = txtLookup;
				btnSearch.onclick = btnSearchClikck;
				document.forms[0].onsubmit = form_onsubmit;
            }

Open in new window

0
Comment
Question by:josephdts
[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
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 41890039
replace :
function window.onload() {
by :
window.onload = function() {

or better use :
if(window.addEventListener){
	window.addEventListener("load", f);
}
else {
	window.attachEvent("onload", f);
}
var f = function() {
	var role = new String("<% =NMUser.Access%>");
	var login = new String("<%=NMUser.LoggedFor %>");
	document.login = login;
	document.role = role;
	var tblMain = document.getElementById("tblMain");
	tblMain.greenBarIt = showGreenBar;
	tblMain.clear = clearTable;
	tblMain.greenBarIt();//showGreenBar();
	tblMain.onmouseout=tblMain_onmouseOut;
	tblMain.AddMailTo= addMailTo;
	tblMain.AddMailTo();
	document.Form1.txtPwd.onkeydown = txtPwd_onkeydown;
	var cboPage = document.getElementById("cboPage");
	cboPage.onchange = cboPage_onchange;
	var txtLookup = document.getElementById("txtLookup");
	txtLookup.tbl = tblMain;
	txtLookup.onkeyup = txtLookupKeyUp;
	txtLookup.onkeydown = txtLookupKeyDown;
	var btnSearch = document.getElementById("btnSearch");
	var anc_createNewMatter = document.getElementById("anc_createNewMatter");
	anc_createNewMatter.onclick = anc_createNewMatter_Click;
	btnSearch.txt = txtLookup;
	btnSearch.onclick = btnSearchClikck;
	document.forms[0].onsubmit = form_onsubmit;
}

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…

739 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