Forums
This topic is locked
Relational validations
Posted 23 Aug 2002 13:02:11
1
has voted
23 Aug 2002 13:02:11 Erwin Hendriks posted:
I need to validate a form in a specific way: If a certain checkbox is checked, other fields must be entered.By the way, I'm using UD4.. I prefer a javascript rooutine to do this.
Suggestions please!
Nakhba
Replies
Replied 23 Aug 2002 16:04:53
23 Aug 2002 16:04:53 Vince Baker replied:
You must add this line anywhere in the form tag:
ONSUBMIT="return checkform();"
This section goes in the head:
<SCRIPT TYPE="text/javascript">
function checkform() {
if (theForm.Checkboxname.value == ""
{ strFIELDNAME=document.FORMNAME.FIELDNAME
if ((strFIELDNAME.value==null)||(strFIELDNAME.value=="")
{
alert("Please enter a Value in the field."
strFIELDNAME.focus()
return false
}
return true
}
</script>
If the initial checkbox is not used then true is returned and the form is processed. If the checkbox is empty the field validation will occur. If you need to add more fields to be validated just copy and paste from:
strFIELDNAME= TO return false
}
And just change the field names.
I have not checked the code so maybe a couple of tweeks are needed but should be ok.
<% Response.write(The best line of code you can ever use"%>
Vince
VBScript | ASP | HTML | SQL | Oracle | Hosting
ONSUBMIT="return checkform();"
This section goes in the head:
<SCRIPT TYPE="text/javascript">
function checkform() {
if (theForm.Checkboxname.value == ""
{ strFIELDNAME=document.FORMNAME.FIELDNAME
if ((strFIELDNAME.value==null)||(strFIELDNAME.value=="")
{
alert("Please enter a Value in the field."
strFIELDNAME.focus()
return false
}
return true
}
</script>
If the initial checkbox is not used then true is returned and the form is processed. If the checkbox is empty the field validation will occur. If you need to add more fields to be validated just copy and paste from:
strFIELDNAME= TO return false
}
And just change the field names.
I have not checked the code so maybe a couple of tweeks are needed but should be ok.
<% Response.write(The best line of code you can ever use"%>
Vince
VBScript | ASP | HTML | SQL | Oracle | Hosting
Replied 30 Aug 2002 11:17:46
30 Aug 2002 11:17:46 Erwin Hendriks replied:
Thanks again for your reaction, Vince;
I will try this at home!
Nakhba
I will try this at home!
Nakhba