- 1). Design your Web form using standard HTML coding. If you don't already have a form set up, you can create one. The following is an example of a small form with only one text box:
<form name="myform">
<input type="text" name="inputtext">
<input type="submit">
</form> - 2). Create a Javascript block after the closing </body> tag and before the closing </HTML> tag of your document by inserting the following code (see the "Tips" section for a working example of how this should appear):
<script type="text/javascript"> </script> - 3). Create a Javascript function to work with the form field tags. You must use each tag's name to edit the properties in the tags. For instance, the following Javascript function adds text to the text box created in step one:
<script type="text/javascript">
document.getElementById("mytextbox").value = "Hello World";
</script>
Notice the first part of the command is "document," which indicates that you want to use the main document loaded in the Web browser; "mytextbox" is the name of the form field, and the "value" property is the text value added to the text box. - 4). Save your changes and then load the HTML file into your Web browser. The page should have a text box and a submit button; the Javascript command has inserted the words "Hello world" into the text box.
previous post
next post