validate_form.js
Tutorial [1/8]: The Basics
[<< < > >>]
view the code
Your job: Make a form having a single text element and a 'go' button. The value of that text box must be (a) provided, and (b) a valid integer between 8 and 20.
This is the most basic implementation of validate_form.js
.
TOP The code [1/8] (try it) [<< < > >>]
Need to upgrade from a previous version?
<HTML><HEAD>
<SCRIPT LANGUAGE="JavaScript1.3" SRC="../../../js_uncompressed/validate_form.js" TYPE="text/javascript"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript1.3">
//<!---
loadVF('../../../js_uncompressed/');
configVF("CIBC_ON", -1);
function submitGoodValues(f_orm) {
f_orm.fav_int.sMsgRequired = "What's your favorite integer?";
f_orm.fav_int.sMsgTxtInt = "Your favorite integer must be an *integer* between ~RANGE_MIN~ and ~RANGE_MAX~, inclusive.";
f_orm.fav_int.iIntMin = 8;
f_orm.fav_int.iIntMax = 20;
var sErrors = getFormErrorMsgs(f_orm, ' - ');
if(sErrors) {
alert('OOPS!\n\n' + sErrors);
return false;
} else {
alert('HOORAY!\n\nForm is "submitted" successfully.\n\nTo submit for real, comment out this alert line, and change the next line to return "true".');
return false;
}
}
//--->
</SCRIPT>
</HEAD><BODY onLoad="completeVFLoad();">
<FORM NAME="form_fav_int" onSubmit="return submitGoodValues(this);" METHOD="post">
What's your favorite integer between 8 and 20? <INPUT TYPE="text" NAME="fav_int" SIZE="20">
<BR><INPUT TYPE="submit" VALUE="Here you go">
</FORM>
</BODY></HTML>
|
Copyright (C) 2003-2005, Jeff Epstein. All rights reserved.