views:

108

answers:

5

Hi All !

I have to code below - works great in IE and Opera, but does not work at all in Firefox / Netscape. Any ideas?

The problem is that nothing happens when clicking printer friendly.

<html>
<head>
  <script type="text/javascript">
    function onPrint()
    {
    window.printForm.submit();
    }
  </script>
</head>
<body>
  <form name="printForm" action="/xasp?print=on" method="post">
    <table>
      <tr>
        <td><input type="checkbox" name="show" onClick="formSubmit();"></td>
      </tr>
    </table>
  </form>
</body>
</html>
A: 

I think you should use document.printForm instead of window.printForm. And in the form tag write "action" not "ction".

mck89
Not standard see w3schools
HollyStyles
Do you want a standard project or a working project?
mck89
@HollyStyles: W3Schools isn't a good place to find out about standards.
David Dorward
@mck89: They aren't mutually exclusive choices. document.forms.printForm is fine. http://www.w3.org/TR/2003/REC-DOM-Level-2-HTML-20030109/html.html
David Dorward
But a lot of important javascript frameworks use non standard methods, so you won't use them because they're non standard? I don't think so, i think that if they work the are standard(for me)
mck89
@mck89: I know what you mean. But I would always maintain document.GetElementById("id") is best if not using a framework. What I should have said is: 'Not a good standard' my bad.
HollyStyles
+4  A: 

You have to get form by id, not by name.

document.getElementById("printForm").submit();
x2
Will that work? printForm isn't an ID.
John Feminella
thanks x2.. it's work...
Fero
Yes it will work but more importantly x2 doesn't say why.
HollyStyles
I revived the original form name from the OP's post. As x2 has noted though, you would still need to update your form to include an ID. Alternatively you can keep the name only, and access it by: window.forms['printForm'].submit();
scunliffe
+1  A: 
document.forms["printForm"].submit();
rahul
A: 
<form name="printForm" ction="/xasp?print=on" method=post>

"ction", what is that? ;) Is this a post typo, or have you misspelled action in the code?

crunchdog
I think this is a typo.
rahul
A: 

I think you need something like:

document.getElementById("printForm").submit();

Referencing the form directly from the window object is not standard, well certainly not supported across all browsers.

HollyStyles