Why in the code below upon the call of document.write in the function validator() the form elements (the checkbox and button) are removed from screen?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function validator() {
if (document.myForm.thebox.checked)
document.write("checkBox is checked");
else
document.write("checkBox is NOT checked");
}
</script>
</head>
<body>
<form name="myForm">
<input type="checkbox" name ="thebox"/>
<input type="button" onClick="validator()" name="validation" value="Press me for validation"/>
</form>
</body>
</html>
document.write()is used to write to the document stream.In your case, the stream is most probably already closed when the onClick handler is called, because your document has finished loading.
Calling
document.write()on a closed document stream automatically callsdocument.open(), which will clear the document.