Solved

JavaScript error

Posted on 2016-11-16
1
32 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 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now