Hi,
I have just started learning Javascript. I want "Hello World!" to be written to a webpage once a user clicks a button. I have tried this:
<html>
<head>
<script type="text/javascript">
function displaymessage()
{
document.write("Hello World!");
}
</script>
</head>
<body>
<form>
<input type="button" value="Click me!" onclick="displaymessage()" />
</form>
</body>
</html>
I can get it to do a window.alert("Hello World!")
but not do document.write("Hello World!")
for some reason. What happens is the button disappears and no text is displayed. My guess is that the problem is in the document.write
but I do not know how to work around it. Any suggestions?