Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print page shows unchanged checkbox in IE with DocType

Strange problem. I have a simple webform where users can fill in text and check/uncheck some checkboxes. When this is printed to pdf or paper (or print preview) in IE (7 or 8) the checkboxes are printed unchanged. E.g. user sets a check, this is printed unchecked ... or with a pre-checked box with the user unchecked, is printed checked.

Same goes for the radio.

Only when I remove the DocType completely, IE prints it correctly. But I need to use XHTML-strict.

This is a simple example which fails in IE:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="nl" xml:lang="nl-NL"> 
<body>
<input type='checkbox' name='y'/><br/>
<input type='radio' name='x'/><br/>
</body>
</html>

Doesn't work with any doctype I tested (loose or html4).

Anyone a idea how to solve this?

Many thanks, Michael

like image 775
Michael Avatar asked Aug 28 '10 16:08

Michael


1 Answers

Turns out to be a IE8 bug: http://webbugtrack.blogspot.com/2009/04/bug-444-ie8-printing-issues-in.html

It's not having this problem with "Compatibility View" turned ON.

A solution is to add the following in the header:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />

Which kinda breaks validation and gives a problem when IE9 comes up.

Other "nice" workaround with JavaScript works also:

<input type='checkbox' name='y' onclick='SetCheck(this)'/>
.....

function SetCheck(el)
{
  if(el)
  {
    if(el.checked)  el.setAttribute('checked','checked');
    else            el.removeAttribute("checked");
  }
}

But when you cannot rely on javascript being turned on, you're screwed by Microsoft.

like image 150
Michael Avatar answered Sep 29 '22 14:09

Michael