JavaScript Chapter 6




Skip to Chapter   1  2  3  4  5  6  7  8  9  10 

                                                              Chapter 6 -- Forms






Forms

You cannot use forms very well without using CGI. If you are making a simple form, however, JavaScript will definitely suffice.
The HTML code to start a form is <form>. You also want to include a name in your form tag so that it can refferenced by your script.
The code for a form with a button, a text field, and a checkbox would look like this:
<form name="form1">
<input type="button" name="button1" value="button">
<input type="text" name="text1" value="text">
<input type="checkbox" name="checkbox1">
checkbox </form>
The actual form would look like this:
         checkbox
We're are going to make a simple password form.
Remember, the input tags must be inside of the <form> and </form> tags.
The value variable in the textfield represents the text that that field has in it.
The following shows how you would use input from a form to create a really pathetic security feature.

Play around with this code and reload the page if you accidentally mess up and can't fix it.

the Confirm Function

The Confirm command brings up a small window in which the user can give a OK/Cancel response.
The code I used for the button was:
<input type="button" onclick="javascript:var temp = confirm('pretty groovy, huh?');" value="See it in action!">
The variable will be equal to true/1 if they hit OK or false/0 if they hit Cancel.
You can use an if statement to see if they hit ok or not i.e.:
var temp = confirm("Hit OK or Cancel");
if (temp == true)
{
alert('you hit OK');
}
if (temp == false)
{
alert('you hit Cancel');
}
Just four more chapters and you will know JavaScript.
Here are some of the things you'll need to remember about forms:
In order to refference an element of a form, you must put the form name first(FormName.FormElement).
The input type password replaces your letters with * only on the screen; To the computer it is still the same letters you typed in.
Never use the code I've given above to secure any part of any website that you want to restrict access to(unless you're willing to risk it).
The seventh chapter will go over functions in javascript and how to use them.
DHTML DHTML Functions