|
-
Mar 8th, 2002, 04:50 AM
#1
Thread Starter
Fanatic Member
Try this : -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Check Form Client Side</title>
<script language="JavaScript" type="text/javascript">
<!--
function checkForm(form){
for (var i = 0; i < form.elements.length; i++) {
var objectID = form.elements[i];
if (objectID.type == 'text' || objectID.type == 'textarea' || objectID.type == 'password' || objectID.type == 'file' ) {
if (objectID.value == '') {
alert('Please fill out the text field ' + objectID.name);
objectID.focus();
return false;
}
}
}
}
//-->
</script>
</head>
<body>
<form name="form1" method="POST" action="process.asp" onsubmit="return checkForm(this)">
<input type="text" name="sometext">
<input type="password" name="somemoretext">
<input type="submit" value="Go!">
</form>
</body>
</html>
It checks the form to see if the text boxes contain text and if it returns false it wont let you continue.
-
Mar 8th, 2002, 01:20 PM
#2
Addicted Member
Client-side error checking is great for the user because they can get quick feed-back without having to wait on a server response. It is often wise, however, to put similar checking on the server-side anyway for security purposes. That way, a malicious hacker will have a more difficult time screwing things up, should one decide to "play" with your html and JavaScripts.
cudabean
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|