Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

JavaScript error

Posted on 2016-11-16
1
Medium Priority
?
107 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
1 Comment
 
LVL 83

Accepted Solution

by:
leakim971 earned 2000 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-…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 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