开发者

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

  1. PrintPayslipPart is not a valid id, and so the getElementById returns null.
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜