A
Andrew Falanga
HI,
Just a warning, I'm a javascript neophyte. I'm writing a function to
validate the contents of a form on a web page I'm developing. Since
I'm a neophyte, this function is quite simple at this time (in fact, I
don't even know if it totally works, I'm still debugging). However,
the first problem is that when an error is encountered, I get my alert
box, I press ok and then the form is submitted and the new data is
entered into the database (and it shouldn't be). Basically, this is
what I've got (without all of the form tags):
in the <head> section of the page:
<script type="text/javascript">
function CheckFormValues() {
var nullsPresent = false;
var npf = document.getElementById("NewPatientForm");
for(var i=0; i < npf.length; i++) {
if(npf.elements.nodeType == "textarea")
continue;
if(npf.elements.value == "") {
nullsPresent = true;
break;
}
}
if(nullsPresent) {
alert("No item on this form may be null (except comments)
\nPlease correct and resubmit");
return;
}
npf.submit();
}
</script>
Then, the submit button (in the form tags):
<input type=button onClick="CheckFormValues()" style="height:40px;font-
size:18px;" value="Submit New Patient" />
What do I need to have in the function to make this function exit so
the user fills in the null strings and then re-submits? As you can
see, I tried a "return;" before the call to nfp.submit(), but that
didn't work. It still submitted the data to the DB.
Thanks,
Andy
Just a warning, I'm a javascript neophyte. I'm writing a function to
validate the contents of a form on a web page I'm developing. Since
I'm a neophyte, this function is quite simple at this time (in fact, I
don't even know if it totally works, I'm still debugging). However,
the first problem is that when an error is encountered, I get my alert
box, I press ok and then the form is submitted and the new data is
entered into the database (and it shouldn't be). Basically, this is
what I've got (without all of the form tags):
in the <head> section of the page:
<script type="text/javascript">
function CheckFormValues() {
var nullsPresent = false;
var npf = document.getElementById("NewPatientForm");
for(var i=0; i < npf.length; i++) {
if(npf.elements.nodeType == "textarea")
continue;
if(npf.elements.value == "") {
nullsPresent = true;
break;
}
}
if(nullsPresent) {
alert("No item on this form may be null (except comments)
\nPlease correct and resubmit");
return;
}
npf.submit();
}
</script>
Then, the submit button (in the form tags):
<input type=button onClick="CheckFormValues()" style="height:40px;font-
size:18px;" value="Submit New Patient" />
What do I need to have in the function to make this function exit so
the user fills in the null strings and then re-submits? As you can
see, I tried a "return;" before the call to nfp.submit(), but that
didn't work. It still submitted the data to the DB.
Thanks,
Andy