Note: Because document.write()
writes to the document stream, calling document.write()
on a closed (loaded) document automatically calls document.open()
, which will clear the document.
Your first call to
document.write
clears the document, so there is no element to find.
Either read the value before calling
document.write
:
function clicked()
{
var a = document.getElementById("number").value;
document.write("submit clicked");
document.write(a);
}
or display the output in some other way - eg: in
the developer console[
^]:
function clicked()
{
console.log("submit clicked");
var a = document.getElementById("number").value;
console.log(a);
}