If you will want to refer back to the FORM elements in a JavaScript (for validation, etc), it is handy to include a NAME element in the FORM tag (see JavaScript? - the rest of the code is at bottom of page):
An element can be accessed either by its element number ( example: document.myForm.elements[9].value )
Or by its assigned name ( example: document.myForm.Email.value )
Note: If using the name, remember they are Case Sensitive
Receiving input from checkboxes can be tricky. If you use a "NAME" that is the same for all of them, you need to receive it in a way that allows multiple values for the same key. Or, you can assign a unique (but similar) name to each checkbox.
Use radio buttons for mutually exclusive choices. The one marked "Checked" is the default.
Note, "SIZE" contains the number of options viewable without scrolling.
And "multiple" allows for more than one selection.
And now, the SCARIEST type of INPUT: Fields
They are scary because the programmer cannot control what the user enters, so they must be accompanied by validation and limits. There are times that you might not want users entering backticks or astericks into a text field.
<TEXTAREA NAME="PELEGROSA" ROWS="4" COLS="40" WRAP="soft" onBlur="validatePelegrosa()" onFocus="this.select()">Whatever you put between the opening and closing tags shows up here!
</TEXTAREA>
<TEXTAREA NAME="Comments" ROWS="3" COLS="40" WRAP="hard" onBlur="validateComments() onFocus="this.select()">Your comments go here
</TEXTAREA >
The values for WRAP are OFF, Physical (same as Hard), or Virtual (same as Soft)
WRAP="OFF" means that the text in the box does not wrap to the next line.
WRAP="Hard" or WRAP="Physical" means that not only does the text wrap in the box, but that the breaks are included in the transmission.
WRAP="Soft" or WRAP="Virtual" means that the text in the box wraps, but it is sent as one long continuous string without breaks.
It is also possible to use an image as a submit button. The coding would look like this:
<INPUT TYPE="image" SRC="../images/submit_off.gif" WIDTH="180" HEIGHT="60" BORDER="0" ALT="Submit"> But, this type of submit button does not do well with JavaScript event handlers inside this tag (better to do validation in form tag if you are using this).
// Function to validate email address.
function validateEmail() {
var emailstring = document.myForm.Email.value;
var at_Index = emailstring.indexOf("@");
var afterAt_sign = emailstring.substring((at_Index + 1), emailstring.length);
// find a dot in the portion of the string after the at sign only
var dotIndex = afterAt_sign.indexOf(".");
// determine dot position in entire string (not just after 'at' portion)
dotIndex = dotIndex + at_Index + 1;
// afterAt_sign will be portion of string from at sign to dot
afterAt_sign = emailstring.substring((at_Index + 1), dotIndex);
// afterDot will be portion of string from dot to end of string
var afterDot = emailstring.substring((dotIndex + 1), emailstring.length);
var beforeAt_sign = emailstring.substring(0,(at_Index));
var regex = /\;|#|\$|%|\^|&|\*|\(|\)|\+|\\|\/|\?|>|<|\{|\}|\,|\[|\]|\`|\|/;
// index of -1 means "not found"
if ((emailstring.indexOf("@") != "-1") &&
(emailstring.length > 5) &&
(afterAt_sign.length > 0) &&
(beforeAt_sign.length > 1) &&
(afterDot.length > 1) &&
! (regex.test(emailstring)) ) {
// window.alert("email good");
return true;
} else {
alert("Please check your email address!");
document.myForm.Email.focus();
return false;
}
}
// Function to validate input.
function validatePelegrosa() {
var PelegrosaString = document.myForm.PELEGROSA.value;
var BadCharsRegex = /=|\;|\$|%|\^|\*|\@|\(|\)|\+|\\|>|<|\{|\}|\,|\[|\]|\`|\|/;
var PelegrosaLength = PelegrosaString.length;
var MaxLength = 160;
var Difference = MaxLength - PelegrosaLength;
if (PelegrosaLength > MaxLength) {
("value is " + PelegrosaLength + " characters long. Please reduce by " + Difference + " characters.");
return false
}
if (BadCharsRegex.test(PelegrosaString) ) {
alert("Please check your input! Bad characters found.");
return false;
} else {
// alert("value is " + PelegrosaLength + " characters long.");
return true;
}
}
// Function to validate input.
function validateComments() {
var CommentsString = document.myForm.Comments.value;
var BadCharsRegex = /=|\;|\$|%|\^|\*|\@|\(|\)|\+|\\|>|<|\{|\}|\,|\[|\]|\`|\|/;
var CommentsLength = CommentsString.length;
var MaxLength = 120;
var Difference = MaxLength - CommentsLength;
if (CommentsLength > MaxLength) {
("value is " + CommentsLength + " characters long. Please reduce by " + Difference + " characters.");
return false
}
if (BadCharsRegex.test(CommentString) ) {
alert("Please check your comments! Bad characters found.");
return false;
} else {
// alert("value is " + CommentsLength + " characters long.");
return true;
}
}
// Function to validate form.
function validateAll() {
var valid = 0;
if (validateEmail() ) {
valid++;
} else {
document.myForm.Emailinput.focus();
return false;
}
if (validatePelegrosa() ) {
valid++;
} else {
document.myForm.PELEGROSA.focus();
return false;
}
if (validateComments() ) {
valid++;
} else {
document.myForm.Comments.focus();
return false;
}
if ( valid < 3 ) {
return false;
} else {
return true;
}
}
// -->
</SCRIPT>
To email please see:
contact.cgi
if you have any comments or questions about this page.