How to Update a Form Field With JavaScript

Form fields are the elements displayed on a webpage that let your readers submit information. The user enters information and clicks the "Submit" button to send it to a database or an email address. You can automate adding text to these form elements using JavaScript.

Instructions

    • 1

      Right-click your HTML file and select "Open With." Double-click "Notepad" to open the file in a simple text editor.

    • 2

      Create your text box. In this example, a date is added to a text box. The text box is first added to the form fields. Add this code between the "<form>" and "</form>" tags in your file:

      <input type="text" name="date">

    • 3

      Create the JavaScript block. This block is where all your code is located. Place this code between the "<head>" and "</head>" tags:

      <script language="javascript"> </script>

    • 4

      Create the code that adds text to the form element. Add any text that helps you organize your submission data. The code is entered within the script tags. The following code adds a date to the text box created in step two:

      document.form.date.value = "8/3/2010";

    • 5

      Click "File" and "Save" in the Notepad menu options. To test the new code, double-click the HTML file to open it in your browser.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured