PDA

View Full Version : Form fields question


Thee Gandalf
04-24-2006, 04:34 PM
How do I tell the form not to be sent unless particular field(s) have info entered properly?

Thanks,
Gändälf
:D

coothead
04-24-2006, 05:09 PM
Hi there Gändälf,

here is thee:) javascript method but bear in mind that, server side validation will still be required....

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script type="text/javascript">
<!--
function checkForFilling() {
if(document.forms[0][0].value=='') {
alert('stop messing about pop\n\nsomething in the box');
return false;
}
return true;
}
//-->
</script>

</head>
<body>

<form action="http://www.google.com" method="get" onsubmit="return checkForFilling()">
<div>
<input type="text" name="foo"/><label> : fill box</label>
<input type="submit" value="submit" />
</div>
</form>

</body>
</html>

Thee Gandalf
04-24-2006, 05:19 PM
Curerntly I'm using the Post method as I'm sending info to the server, but if server side validation is going to be required, then I would have to use the Get method, wouldn't I?

coothead
04-24-2006, 05:29 PM
Hi there Gändälf,

No, use post. I use google for form testing and forgot to remove before posting. :o
<form action="#" method="post" onsubmit="return checkForFilling()">