Aline: checkbox automatisch markieren

Beitrag lesen

Hi!

ich möchte per Javascript eine checlbox hinzufügen, die automatisch vorausgewählt ist.

Bei Firefox und Opera ist die Checkbox markiert; nur beim IE 7 und 8 nicht.

Ajktuell funktioniert mein, auf das wesentliche gekürzte, Beispiel leider nicht - warum weiß ich jetzt nicht.

Warum funktioniert das gekürzte Beispiel nicht und warum zeigt nur der IE, wenn das Beispiel funktioniert, die checkbox nicht markiert an?

<?xml version="1.0" encoding="utf-8"?>  
<!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" dir="ltr" lang="de" xml:lang="de">  
<head>  
<title>Test</title>  
<meta http-equiv="Content-Type" content="text/html, charset=utf-8" />  
<script type="text/javascript">  
<!--  
[code lang=javascript]// <![CDATA[  
var i1 = 0;  
var i2 = 0;  
  
function test(){  
  i1++;  
  i2++;  
  
  var p = document.getElementById("p");  
  var br1 = document.createElement("br");  
  var input1  = document.createElement("input");  
  var input1Text = document.createTextNode("Input 1");  
  var br2 = document.createElement("br");  
  var input2  = document.createElement("input");  
  var input2Text = document.createTextNode("Input 2");  
  
  input1.type = "checkbox";  
  input1.name = "input[" + i1 + "]";  
  input1.value = "1";  
  input1.checked = true;  
  
  input2.type = "checkbox";  
  input2.name = "input[" + i2 + "]";  
  input2.value = "1";  
  input2.checked = "checked";  
  
  p.appendChield(input1Text);  
  p.appendChield(input1);  
  p.appendChield(br1);  
  
  p.appendChield(input2Text);  
  p.appendChield(input2);  
  p.appendChield(br2);  
  
}  
// ]]>

//-->
</script>
</head>
<body>
<form action="">
<p id="p"></p>
<p><input type="button" value="test" onclick="test();" /></p>
</form>
</body>
</html>[/code]