Solved

JavaScript error

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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

696 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