Home >Web Front-end >JS Tutorial >Why do Form Elements Disappear After Executing Document.write?
Document.write Clears Form Elements
Issue:
Upon executing document.write within the validator() function, the checkbox and button elements disappear from the page.
Explanation:
document.write() writes to the document stream. When the validator() function is called via the button's onClick handler, the document has likely finished loading and the stream is closed.
Calling document.write() on a closed document stream automatically invokes document.open(), which clears the document. Consequently, the form elements are removed from the screen.
The above is the detailed content of Why do Form Elements Disappear After Executing Document.write?. For more information, please follow other related articles on the PHP Chinese website!