Javascript error : object required
I am calling a javascript function in a button in aspx page like
OnClientClick= "printText(document.getElementById('PrintPayslipPart').innerHTML)"
and function is;
function printText(elem)
{
PrintPaySlip = window.open('RP_PrintPaySlip.html','PrintPaySlip','toolbar=no,menubar=yes,width=1000, Height = 700, resizable=yes,scrollbar=Yes');
PrintPaySlip.document.open();
PrintPaySlip.document.write("<html><head>");
PrintPaySlip.document.write("</head><body onload='print()'>");
PrintPaySlip.document.write(elem);
PrintPaySlip.document.write("</body></html>");
PrintPaySlip.document.close();
}
I am using .net 3.5
and ajaxcontrolltoolkit 3.5.40412.2
When cl开发者_开发问答icking on button the error shows as "Microsoft JScript runtime error: Object required".
My guess is that either
PrintPayslipPart
is not a valid id, and so thegetElementById
returns null.PrintPaySlip is not a global variable, and your environment doesn't allow it to be implicitly defined, which could be solved by declaring it local using
var
var PrintPaySlip = window.open(...);
The second one seems more likely.
HTH
first thing i will suggest to you is have Firefox with error console installed and then test the site. At least it can help you find what exactly error is instead of "Microsoft JScript runtime error"
Trust me but Firefox + FireBug + Error Console make life much better for Web (JS) developer.
精彩评论