aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes why the checkbox is not check? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "why the checkbox is not check?" Watch "why the checkbox is not check?" New topic
Author

why the checkbox is not check?

Lu Jin
Greenhorn

Joined: Feb 22, 2003
Posts: 17
I use the following code to generate a checkbox and want to set it to checked. but it's not checked after loaded, anybody can tell me the reason?

thanks!



SCJP, SCWCD, SCBCD, OCA, Next-->SCEA
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61658
    
  67

What browser are you testing in? Your code worked fine for me in Safari and Firefox.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lu Jin
Greenhorn

Joined: Feb 22, 2003
Posts: 17
My browser is IE6
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

What is the "data" element ? And when are you calling init()?

(by the way, it worked for me too)
[ November 13, 2006: Message edited by: Satou kurinosuke ]

[My Blog]
All roads lead to JavaRanch
Krishna Nagadev
Ranch Hand

Joined: Jan 04, 2005
Posts: 32
Change your code like this.. this would help you out

function init()
{
var input = document.createElement("input");
input.type = "checkbox";
input.id = "test";
input.name = "test";

document.getElementById("data").appendChild(input);
document.getElementById('test').checked=true;
}
 
jQuery in Action, 2nd edition
 
subject: why the checkbox is not check?