Page 184 - DCAP408_WEB_PROGRAMMING
P. 184
Web Programming
Notes There are two main methods for validating forms: server-side (using CGI scripts, ASP, etc.), and
client-side (usually done using JavaScript). Server-side validation is more secure but often more
tricky to code, whereas client-side (JavaScript) validation is easier to do and quicker too (the
browser doesn’t have to connect to the server to validate the form, so the user finds out instantly
if they’ve missed out that required field!).
Figure 6.4: Client-side form Validation (usually with
JavaScript Embedded in the Web Page)
Figure 6.5: Server-side form Validation
(usually Performed by a CGI or ASP Script)
Required Fields
The function below checks if a required field has been left empty. If the required field is blank,
an alert box alerts a message and the function returns false. If a value is entered, the function
returns true (means that data is OK):
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==””)
{
178 LOVELY PROFESSIONAL UNIVERSITY