Forums

This topic is locked

Relational validations

Posted 22 years ago
1
has voted
22 years ago 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 22 years ago
22 years ago 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
Replied 22 years ago
22 years ago Erwin Hendriks replied:
Thanks again for your reaction, Vince;

I will try this at home!

Nakhba

Reply to this topic