You validate the form using javascipt. A simple function to validate whether or not a textbox is empty is
- function isEmpty(textbox) {
-
if(textbox.value == "") {
-
return true;
-
}
-
else {
-
return false;
-
}
-
}
To use it just call it with the name of the box
eg
-
function validateClients(form) {
-
if(isEmpty(form.name)) {
-
alert("Client creation cannot proceed without name");
-
form.name.focus();
-
return false;
-
}
-
}
on your form tag just do something like
- <FORM name="myForm" onSubmit = "return validateClientClient(this)">
Thx r035198x, but i'm still confused, with the code you gave, here's what i did:
<script language="JavaScript" type="text/JavaScript">
function validateClients(form1) {
if(isEmpty(form1.CName)) {
alert("Enter your company's name");
form1.CName.focus();
return false;
}
}
//-->
</script>
Here, form1 – name of the form, CName – is the name of a textbox value in the form, I’m not sure if I wrote the code properly. Where you placed Clients in validateClients, I know it was just an eg. But what does it refer to? Also is there a return true, that’s supposed to be in there somewhere?
I put this script just above the form tag. I was unsure of where to put the script, because there is another script at the top in the <head> of the page.
For the form tag you wrote onSubmit = "return validateClientClient(this)", what does the (this) refer to and is Client supposed to be put twice?
Thx again