Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

JavaScript error

Posted on 2016-11-16
1
Medium Priority
?
102 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 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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

636 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