1

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 clicking on button the error shows as "Microsoft JScript runtime error: Object required".

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

5 Comments

It is true that it would be better to declare PrintPaySlip using var, but it won't be stopping the code from working.
@Tim; I know it shouldn't but I have had IE bite me on this (worked flawlessly in all other browsers), I'm not sure in what circumstances this happens, but now that you mention it, I think the error message was different.
You're right actually, there's a case I forgot: IE automatically adds properties to the global object (effectively global variables) corresponding to element IDs and doesn't like you trying to assign to these properties, so if you had an element in the document whose id was "PrintPayslipPart" then IE would throw an error if you didn't use var.
@Tim; ah, so that was what's been causing it! Thanks for clearing this up for me!
I think Chrome does the same thing too but possibly doesn't prevent you from assigning to the global object properties corresponding to element IDs.
0

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.

1 Comment

Except for hunting down the IE bugs, which (unfortunately) are usually numerous.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.