Here is an example that we can use to make sure that a JavaScript function is working properly.
To make it simple, I put the JavaScript and the HTML on one page. That is NOT good practice in general. Here is the code. Put it onto a page called formtest.html in your htdocs directory:
<script language = "JavaScript">
function writeMessage(form){
form.usermessage.value = 'Hi, ' + form.username.value
+ '. How are you?';
}
</script>
<form method = "post">
Enter your name, press the "submit" button, and you will receive a message.<p>
Name
<input type = "text" name = "username">
<input type = "button" name = "submit" value =
"submit" onClick = "writeMessage(this.form)">
<p>
Message
<input type = "text" name = "usermessage" size = "40">
</form>
When you get this to work, then you should move the script to a separate page. Cut the code