Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp: ckbx validation not working if rest of form filled out

Status
Not open for further replies.

selaine

Programmer
Oct 11, 2001
85
US
I have a form on Supplier_reg.asp that asks the user for different information and asks them to select one or more checkboxes. I found this validation script on creativeprogrammers.com (which doesn't exist right now) and am using it for all validation except for my checkboxes (i tried inserting the custom validation into it and it wasn't working) I've run various validation tests on the page and the one I'm having trouble with is making sure at least one checkbox has been selected) - I think the problem may be that I'm trying to run two different scripts at one time, but I'm not sure.


Here is my code for supplier_reg.asp:

<html>
<head>
<title></title>

<script LANGUAGE=&quot;JavaScript&quot;>

function isChecked(frm) {
if ((!(frm.ck_Automotive.checked)) || (!(frm.ck_BldgMat.checked)) || (!(frm.ck_Chemicals.checked)) || (!(frm.ck_Computing.checked)) || (!(frm.ck_ConstrucContr.checked)) || (!(frm.ck_FloorCvrng.checked)) || (!(frm.ck_FormsPP.checked)) || (!(frm.ck_FurnitureOfc.checked)) || (!(frm.FurnitureOT.checked)) || (!(frm.ck_HVAC.checked)) || (!(frm.ck_Insulation.checked)) || (!(frm.ck_Insurance.checked)) || (!(frm.ck_Janitorial.checked)) || (!(frm.ck_LawnEquip.checked)) || (!(frm.ck_MailRoom.checked)) || (!(frm.ck_Medical.checked)) || (!(frm.ck_OfficeEquip.checked)) || (!(frm.ck_OfcSupplies.checked)) || (!(frm.ck_Other.checked)) || (!(frm.ck_Playground.checked)) || (!(frm.ck_RadioTelephone.checked)) || (!(frm.ck_RefuseWaste.checked)) || (!(frm.ck_Roofing.checked)) || (!(frm.ck_SnowRemEquip.checked)) || (!(frm.ck_OfficeEquip.checked)))
{
alert(&quot;Please select at least one of the major categories!&quot;);
return false;
}
else
{
return true;
}
}

</script>

<script language=&quot;JavaScript&quot; src=&quot;gen_validatorv2.js&quot; type=&quot;text/javascript&quot;></script>
</head>

<body>
<center>
<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH=&quot;90%&quot; >
<tr>
<td>
<font face=&quot;Arial,Helvetica&quot; size=-1>
By completing and submitting this form, you will be added to our Supplier List
</td>
</tr>
</table>
</center>

<table BORDER CELLSPACING=0 CELLPADDING=2 WIDTH=&quot;100%&quot; BGCOLOR=&quot;#C7C8C9&quot; >
<tr>
<td>
<form name=&quot;supplyreg&quot; method=&quot;post&quot; action=&quot;commodities.asp&quot;>
<center>
<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH=&quot;85%&quot; >
<tr ALIGN=LEFT VALIGN=TOP>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Company Name </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Company&quot; size=&quot;35&quot; maxlength=&quot;35&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Address </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Address&quot; size=&quot;45&quot; maxlength=&quot;45&quot;></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>City, State, Zip </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_City&quot; size=&quot;35&quot; maxlength=&quot;35&quot;><input type=&quot;text&quot; name=&quot;D_State&quot; size=&quot;2&quot; maxlength=&quot;2&quot;><input type=&quot;text&quot; name=&quot;D_Zip&quot; size=&quot;5&quot; maxlength=&quot;5&quot;></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Phone </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Phone&quot; size=&quot;14&quot; maxlength=&quot;14&quot;></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Fax </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Fax&quot; size=&quot;14&quot; maxlength=&quot;14&quot;></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Website Address </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Website&quot; size=&quot;50&quot; maxlength=&quot;50&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Contact Person </font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Contact&quot; size=35 maxlength=35></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Contact Phone</font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_CPhone&quot; size=14 maxlength=14></td>
</tr>
<tr ALIGN=LEFT VALIGN=TOP>
<td></td>
<td></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot;><font size=-1><font color=&quot;#000000&quot;>Contact Email</font><font color=&quot;#CC0000&quot;>(Please check for accuracy prior to submission)</font></font></font></b></td>
<td><input type=&quot;text&quot; name=&quot;D_Email&quot; size=40 maxlength=40></td>
</tr>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</center>

<center>
<table BORDER=0 CELLSPACING=0 CELLPADDING=3 WIDTH=&quot;85%&quot; >
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#009900&quot;>Please notify me by e-mail </font></font></b><input type=&quot;checkbox&quot; name=&quot;notify&quot; value=&quot;-1&quot;></td>
<td></td>
</tr>
<tr>
<td></td>
<td><input type=&quot;hidden&quot; name=&quot;hidDate&quot;></td>
</tr>
</table>
</center>

<center>
<table BORDER=0 COLS=1 WIDTH=&quot;98%&quot; >
<tr>
<td>
<center>
<table BORDER=0 CELLSPACING=5 CELLPADDING=5 WIDTH=&quot;90%&quot; >
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#000000&quot;><font size=-1>Products and/or Services: </font></font></font></b><br><b><font face=&quot;Arial,Helvetica&quot;><font color=&quot;#CC0000&quot;><font size=-1>(Please select from the General Categories below:)</font></font></font></b></td>
<td></td>
<td></td>
</tr>
</table>
</center>

<center>
<table BORDER CELLSPACING=5 CELLPADDING=5 WIDTH=&quot;90%&quot; >
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Automotive</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Automotive&quot; value=&quot;1000&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Building Materials</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_BldgMat&quot; value=&quot;1200&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Chemicals</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Chemicals&quot; value=&quot;1400&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Computing/Networking</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Computing&quot; value=&quot;1600&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Construction/Contractors</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_ConstrucContr&quot; value=&quot;1800&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Floor Covering</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_FloorCvrng&quot; value=&quot;2000&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Forms, Pre-Printed</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_FormsPP&quot; value=&quot;2200&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Furniture, Office</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_FurnitureOfc&quot; value=&quot;2400&quot;></td>
</tr>
<tr VALIGN=TOP>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Furniture, Other than Office</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_FurnitureOT&quot; value=&quot;2600&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>HVAC: Heating-Ventilation-Air Conditioning</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_HVAC&quot; value=&quot;2800&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Insulation</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Insulation&quot; value=&quot;3000&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Insurance</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Insurance&quot; value=&quot;3200&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Janitorial</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Janitorial&quot; value=&quot;3400&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Lawn Equipment & Accessories</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_LawnEquip&quot; value=&quot;3600&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Mail Room Equipment</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_MailRoom&quot; value=&quot;3800&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Medical</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Medical&quot; value=&quot;4000&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Office Equipment</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_OfficeEquip&quot; value=&quot;4200&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Office Supplies</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_OfcSupplies&quot; value=&quot;4400&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Other (Pest Control)</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Other&quot; value=&quot;4600&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Playground Equipment</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Playground&quot; value=&quot;4800&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Radio/Telephone Equipment & Supplies</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_RadioTelephone&quot; value=&quot;5000&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Refuse & Waste Removal</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_RefuseWaste&quot; value=&quot;5200&quot;></td>
</tr>
<tr>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Roofing</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_Roofing&quot; value=&quot;5400&quot;></td>
<td></td>
<td><b><font face=&quot;Arial,Helvetica&quot; size=-1>Snow Removal & Equipment</font></b></td>
<td><input type=&quot;checkbox&quot; name=&quot;ck_SnowRemEquip&quot; value=&quot;5600&quot;></td>
</tr>
</table>
</center>
</td>
</tr>
</table>
</center>

<center>
<table BORDER=0 CELLSPACING=5 CELLPADDING=5 WIDTH=&quot;60%&quot; >
<tr>
<td>
<center>
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Register&quot; onClick='isChecked(this.form)'>
</center>
</td>
<td><input type=&quot;reset&quot; name=&quot;Reset&quot; value=&quot;Reset&quot;></td>
</tr>
</table>
</center>
</form>

<script language=&quot;Javascript&quot;>
var frmvalidator = new Validator(&quot;supplyreg&quot;);

frmvalidator.addValidation(&quot;D_Company&quot;, &quot;req&quot;, &quot;Please enter your Company Name&quot;);
frmvalidator.addValidation(&quot;D_Company&quot;, &quot;maxlen=35&quot;, &quot;Maximum length for this field is 35 characters&quot;);

frmvalidator.addValidation(&quot;D_Address&quot;, &quot;req&quot;, &quot;Please enter your Company Mailing Address&quot;);
frmvalidator.addValidation(&quot;D_Address&quot;, &quot;maxlen=45&quot;, &quot;Maximum length for this field is 45 characters&quot;);

frmvalidator.addValidation(&quot;D_City&quot;, &quot;req&quot;, &quot;Please enter the City for the Company Mailing Address&quot;);
frmvalidator.addValidation(&quot;D_City&quot;, &quot;maxlen=35&quot;, &quot;Maximum length for this field is 35 characters&quot;);

frmvalidator.addValidation(&quot;D_State&quot;, &quot;req&quot;, &quot;The state is a required field&quot;);
frmvalidator.addValidation(&quot;D_State&quot;, &quot;maxlen=2&quot;, &quot;Maximum length for this field is 2 characters&quot;);

frmvalidator.addValidation(&quot;D_Zip&quot;, &quot;req&quot;, &quot;Please enter a 5-digit zip code&quot;);
frmvalidator.addValidation(&quot;D_Zip&quot;, &quot;maxlen=5&quot;, &quot;Maximum length for this field is 5 characters&quot;);

frmvalidator.addValidation(&quot;D_Phone&quot;, &quot;req&quot;, &quot;Please enter an Area Code and Phone Number for your Company&quot;);
frmvalidator.addValidation(&quot;D_Phone&quot;, &quot;maxlen=14&quot;, &quot;Maximum length for this field is 14 characters&quot;);

frmvalidator.addValidation(&quot;D_Fax&quot;, &quot;maxlen=14&quot;, &quot;Maximum length for this field is 14 characters&quot;);

frmvalidator.addValidation(&quot;D_Website&quot;, &quot;maxlen=50&quot;, &quot;Maximum length for this field is 50 characters&quot;);

frmvalidator.addValidation(&quot;D_Contact&quot;, &quot;req&quot;, &quot;Please enter a Contact Name&quot;);
frmvalidator.addValidation(&quot;D_Contact&quot;, &quot;maxlen=35&quot;, &quot;Maximum length for this field is 35 characters&quot;);

frmvalidator.addValidation(&quot;D_CPhone&quot;, &quot;req&quot;, &quot;Please enter an Area Code and Phone Number for your Contact Person&quot;);
frmvalidator.addValidation(&quot;D_CPhone&quot;, &quot;maxlen=14&quot;, &quot;Maximum length for this field is 14 characters&quot;);

frmvalidator.addValidation(&quot;D_Phone&quot;, &quot;req&quot;, &quot;Please enter an Email address&quot;);
frmvalidator.addValidation(&quot;D_Phone&quot;, &quot;maxlen=40&quot;, &quot;Maximum length for this field is 40 characters&quot;);

frmvalidator.addValidation(&quot;D_Email&quot;, &quot;email&quot;);

</script>
</td>
</tr>
</table>
</center>

</body>

</html>



Here is my code for the form validation except for checkboxes:

/*
* The Validator
* The class that handles all validation related issues
*
* pass the name of the form while constructing.
* methods:
* addValidation(input_item_name,validation_descriptor,error_string)
* call this method for each input item. Single input item can have
* many validations
*
* setAddnlValidationFunction(functionname)
* call this function to set a custom validate function, which will
* be called after other validations are over.
* The function should return 'true' or 'false'
*/
function Validator(frmname)
{
this.formobj=document.forms[frmname];
if(!this.formobj)
{
alert(&quot;BUG: could not get Form object &quot;+frmname);
return;
}
if(this.formobj.onsubmit)
{
this.formobj.old_onsubmit = this.formobj.onsubmit;
this.formobj.onsubmit=null;
}
else
{
this.formobj.old_onsubmit = null;
}
this.formobj.onsubmit=form_submit_handler;
this.addValidation = add_validation;
this.setAddnlValidationFunction=set_addnl_vfunction;
this.clearAllValidations = clear_all_validations;
}

function set_addnl_vfunction(functionname)
{
this.formobj.addnlvalidation = functionname;

}
function clear_all_validations()
{
for(var itr=0;itr < this.formobj.elements.length;itr++)
{
this.formobj.elements[itr].validationset = null;
}
}
function form_submit_handler()
{
for(var itr=0;itr < this.elements.length;itr++)
{
if(this.elements[itr].validationset &&
!this.elements[itr].validationset.validate())
{
return false;
}
}
if(this.addnlvalidation)
{
str =&quot; var ret = &quot;+this.addnlvalidation+&quot;()&quot;;
eval(str);
if(!ret) return ret;
}
return true;
}

function add_validation(itemname,descriptor,errstr)
{
if(!this.formobj)
{
alert(&quot;BUG: the form object is not set properly&quot;);
return;
}//if
var itemobj = this.formobj[itemname];
if(!itemobj)
{
alert(&quot;BUG: Could not get the input object named: &quot;+itemname);
return;
}

if(!itemobj.validationset)
{
itemobj.validationset = new ValidationSet(itemobj);
}
itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
this.desc=desc;
this.error=error;
this.itemobj = inputitem;
this.validate=vdesc_validate;
}
function vdesc_validate()
{
if(!V2validateData(this.desc,this.itemobj,this.error))
{
this.itemobj.focus();
return false;
}
return true;
}


function ValidationSet(inputitem)
{
this.vSet=new Array();
this.add= add_validationdesc;
this.validate= vset_validate;
this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
this.vSet[this.vSet.length]=
new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
for(var itr=0;itr<this.vSet.length;itr++)
{
if(!this.vSet[itr].validate())
{
return false;
}
}
return true;
}

//---------------------------------EMail Check ------------------------------------

/* checks the validity of an email address entered
* returns true or false
*
*/

function validateEmailv2(email)
{
// a very simple email validation checking.
// you can add more complex email checking if it helps
var splitted = email.match(&quot;^(.+)@(.+)$&quot;);
if(splitted == null) return false;
if (email == &quot;&quot;) { // can be empty
return true;
}

if(splitted[1] != null )
{
var regexp_user=/^\&quot;?[\w-_\.]*\&quot;?$/;
if(splitted[1].match(regexp_user) == null) return false;
}
if(splitted[2] != null)
{
var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
if(splitted[2].match(regexp_domain) == null)
{
var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
if(splitted[2].match(regexp_ip) == null) return false;
}// if
return true;
}
return false;
}


/* function V2validateData
* Checks each field in a form

*/
function V2validateData(strValidateStr,objValue,strError)
{
var epos = strValidateStr.search(&quot;=&quot;);
var command = &quot;&quot;;
var cmdvalue = &quot;&quot;;
if(epos >= 0)
{
command = strValidateStr.substring(0,epos);
cmdvalue = strValidateStr.substr(epos+1);
}
else
{
command = strValidateStr;
}

switch(command)
{
case &quot;req&quot;:
case &quot;required&quot;:
{
if(eval(objValue.value.length) == 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name + &quot; : Required Field&quot;;
}//if
alert(strError);
return false;
}//if
break;
}//case required
case &quot;maxlength&quot;:
case &quot;maxlen&quot;:
{
if(eval(objValue.value.length) > eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + &quot; : &quot;+cmdvalue+&quot; characters maximum &quot;;
}//if
alert(strError + &quot;\n[Current length = &quot; + objValue.value.length + &quot; ]&quot;);
return false;
}//if
break;
}//case maxlen
case &quot;minlength&quot;:
case &quot;minlen&quot;:
{
if(eval(objValue.value.length) < eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + &quot; : &quot; + cmdvalue + &quot; characters minimum &quot;;
}//if
alert(strError + &quot;\n[Current length = &quot; + objValue.value.length + &quot; ]&quot;);
return false;
}//if
break;
}//case minlen
case &quot;alnum&quot;:
case &quot;alphanumeric&quot;:
{
var charpos = objValue.value.search(&quot;[^A-Za-z0-9]&quot;);
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+&quot;: Only alpha-numeric characters allowed &quot;;
}//if
alert(strError + &quot;\n [Error character position &quot; + eval(charpos+1)+&quot;]&quot;);
return false;
}//if
break;
}//case alphanumeric
case &quot;num&quot;:
case &quot;numeric&quot;:
{
var charpos = objValue.value.search(&quot;[^0-9]&quot;);
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+&quot;: Only digits allowed &quot;;
}//if
alert(strError + &quot;\n [Error character position &quot; + eval(charpos+1)+&quot;]&quot;);
return false;
}//if
break;
}//numeric
case &quot;alphabetic&quot;:
case &quot;alpha&quot;:
{
var charpos = objValue.value.search(&quot;[^A-Za-z]&quot;);
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+&quot;: Only alphabetic characters allowed &quot;;
}//if
alert(strError + &quot;\n [Error character position &quot; + eval(charpos+1)+&quot;]&quot;);
return false;
}//if
break;
}//alpha
case &quot;alnumhyphen&quot;:
{
var charpos = objValue.value.search(&quot;[^A-Za-z0-9\-_]&quot;);
if(objValue.value.length > 0 && charpos >= 0)
{
if(!strError || strError.length ==0)
{
strError = objValue.name+&quot;: characters allowed are A-Z,a-z,0-9,- and _&quot;;
}//if
alert(strError + &quot;\n [Error character position &quot; + eval(charpos+1)+&quot;]&quot;);
return false;
}//if
break;
}
case &quot;email&quot;:
{
if(!validateEmailv2(objValue.value))
{
if(!strError || strError.length ==0)
{
strError = &quot;Please enter a valid Email address &quot;;
}//if
alert(strError);
return false;
}//if
break;
}//case email
case &quot;lt&quot;:
case &quot;lessthan&quot;:
{
if(isNaN(objValue.value))
{
alert(objValue.name+&quot;: Should be a number &quot;);
return false;
}//if
if(eval(objValue.value) >= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + &quot; : value should be less than &quot;+ cmdvalue;
}//if
alert(strError);
return false;
}//if
break;
}//case lessthan
case &quot;gt&quot;:
case &quot;greaterthan&quot;:
{
if(isNaN(objValue.value))
{
alert(objValue.name+&quot;: Should be a number &quot;);
return false;
}//if
if(eval(objValue.value) <= eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name + &quot; : value should be greater than &quot;+ cmdvalue;
}//if
alert(strError);
return false;
}//if
break;
}//case greaterthan
case &quot;regexp&quot;:
{
if(!objValue.value.match(cmdvalue))
{
if(!strError || strError.length ==0)
{
strError = objValue.name+&quot;: Invalid characters found &quot;;
}//if
alert(strError);
return false;
}//if
break;
}//case regexp
case &quot;dontselect&quot;:
{
if(objValue.selectedIndex == null)
{
alert(&quot;BUG: dontselect command for non-select Item&quot;);
return false;
}
if(objValue.selectedIndex == eval(cmdvalue))
{
if(!strError || strError.length ==0)
{
//strError = objValue.name+&quot;: Please Select one option &quot;;
alert(strError);
}//if
alert(strError);
return false;
}
break;
}//case dontselect
}//switch

FMdate = new Date();
Curdate = (FMdate.getMonth()+1) +&quot;/&quot;+ FMdate.getDate() + &quot;/&quot; + FMdate.getYear()
document.supplyreg.hidDate.value = Curdate;

return true;

}

Can anyone tell me why this isn't working. The alert box pops up as long as one of the other parts of the form aren't filled out correctly, but if all parts are filled out correctly, it continues on to commodities.asp????? I've been looking at this all day and am pulling out my hair. Any suggestions????? Sorry about the length on this one...... Thanks to all!!!!!!!!![nosmiley]
 
Here's somewhere to start:

1: Does your code work without the other validation
2: It might help to use the javascript array document.forms[0].elements to loop through all the checkboxes on your form and have a variable to count the number that are checked. This should work better (and in 3 lines of code) than the mammoth logic check you have now.
 
1)I removed the genvalidatorv2.js and all of its script
references and it gives me the alert box, but when I
click ok on the alert box it moves on to commodities.asp

2)As far as the array issue, I have one checkbox on the
form that shouldn't be part of the count type validation
(the email notification checkbox). Plus, I'm a learning
as I go and need to know how web programmer and have
never worked with arrays.

It would be terrific if I could incorporate the count
checkboxes validation into the genvalidatorv2.js script, but
have been unable to figure it out. According to the documentation that came with it, this is how its supposed to work::::

Adding Custom Validation:
If you want to add a custom validation, which is not provided by the validation descriptors, you can do so. Here are the steps:
Create a javascript function which returns true or false depending on the validation.

function DoCustomValidation()
{
var frm = document.forms[&quot;myform&quot;];
if(frm.pwd1.value != frm.pwd2.value)
{
alert('The Password does not match!');
return false;
}
else
{
return true;
}
}


Associate the validation function with the validator
object.

frmvalidator.setAddnlValidationFunction(&quot;DoCustomValidation&quot;);

The custom validation function will be called automatically after other validations.

??????? Any suggestions??
 
it looks like you might not be allowed to pass form directly into your new function (i.e. the function is fine, but it won't work as it needs parameters)

I'd have to look at it more closely.

To keep it from submitting using your code, change the submit button from
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Register&quot; onClick='isChecked(this.form)'>
to
<input type=&quot;button&quot; name=&quot;Submit&quot; value=&quot;Register&quot; onClick='isChecked(this.form)'>

and then add the following line to isChecked(frm) immediately before the return true one:
frm.submit();
 
I think I read in the documentation for the genvalidatorv2.js that you aren't supposed to use onclick with the submit button if you're using the script file, so I think I need to figure out how to incorporate my checkbox validation into the custom validation code. But looking at the genvalidatorv2.js its beyond me......

I'll try your suggestion and see if it helps. Then let you know.
 
Tried your suggestion and no processing takes place other than the checkbox verification code and it won't continue on to the next page no matter what....
 
Ok, try taking out the last suggestion (setting button back to submit)

and something like the following function:

function DoCustomValidation()
{
var frm = document.forms[&quot;supplyreg&quot;];
if ((!(frm.ck_Automotive.checked)) || (!(frm.ck_BldgMat.checked)) || (!(frm.ck_Chemicals.checked)) || (!(frm.ck_Computing.checked)) || (!(frm.ck_ConstrucContr.checked)) || (!(frm.ck_FloorCvrng.checked)) || (!(frm.ck_FormsPP.checked)) || (!(frm.ck_FurnitureOfc.checked)) || (!(frm.FurnitureOT.checked)) || (!(frm.ck_HVAC.checked)) || (!(frm.ck_Insulation.checked)) || (!(frm.ck_Insurance.checked)) || (!(frm.ck_Janitorial.checked)) || (!(frm.ck_LawnEquip.checked)) || (!(frm.ck_MailRoom.checked)) || (!(frm.ck_Medical.checked)) || (!(frm.ck_OfficeEquip.checked)) || (!(frm.ck_OfcSupplies.checked)) || (!(frm.ck_Other.checked)) || (!(frm.ck_Playground.checked)) || (!(frm.ck_RadioTelephone.checked)) || (!(frm.ck_RefuseWaste.checked)) || (!(frm.ck_Roofing.checked)) || (!(frm.ck_SnowRemEquip.checked)) || (!(frm.ck_OfficeEquip.checked))) {
alert('Click a box...');
return false;
}
else
{
return true;
}
}

and remember the

frmvalidator.setAddnlValidationFunction(&quot;DoCustomValidation&quot;);

line
 
Well, we're getting there.... I tried your suggestion but there remains a problem. All other validation are determined prior to the checkbox validation, which according to the genvalidatorv2.js documentation is the way its supposed to work. All validation works correctly, including the checkbox validation with one exception:

If I leave all checkboxes (not including the email one - which is not supposed to be part of the DoCustomValidation function) unchecked and click &quot;Submit&quot; the alert pops up saying &quot;Click a box...&quot;. However, if I then select a box or two or whatever, I still get the alert &quot;Click a box...&quot; and the page doesn't process.

Any clues???
 
I would suggest two steps,

1: trying the custom validation to only test one checkbox and see if that works correctly
2: If it does make sure the logic I wrote out works correctly outside of the validator.

If the custom validation works with one checkbox AND that logic is right, then we have a rather big problem
 
hi!
without going into this code too much...
why so many check boxes...why not drop list.menu?
is this just validation &quot;for the correct input&quot; (eg. email must be in format q@q.com...) or is it conditional?
what are the requred fields on the form?
I will gladly generate workin script for you!
If u have Dreamweaver handy this is a matter of few seconds....
up to you
all the best!


> need more info?
:: don't click HERE ::
 
I noticed one thing is your complex or statement would mean that all the boxes would need to be checked or you will receive the message - because it checks if not checked or not checked if one is checked does not mean all the options would be checked - hope this helps - happy programming
 
Thanks bduke - that was the problem. I simply changed the || to && and that solved the problem!!! Duh!~!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top