/    Sign up×
Community /Pin to ProfileBookmark

form validation

I have form validation script (gen_validatorv31.js) that works fine but I am trying to disable some parts of it depending on the form fields.
Part of the validation script that has all of the field names and custom messages goes bellow the form on the page. What I am trying to do is disable some of the field checks if one of the fields is not empty. I am not that good with JS but I think the problem is that this script is bellow the form so it on form load it sees that that field is blank and doesn’t look for changes again. So how can I make it so the script on the bottom of the page looks at the form fields again?

[CODE]
<form name=”myForm”>…</form>
<script language=”JavaScript” type=”text/javascript”>
var frmvalidator = new Validator(“myForm”);
frmvalidator.EnableMsgsTogether();

if (document.myForm.Finance_Code.value == “”)
{

frmvalidator.addValidation(“Billing_Type”,”dontselect=0″,”Credit Card Type: Plase select one option”);
frmvalidator.addValidation(“Billing_Number”,”req”,”Please enter your Credit Card Number”);
frmvalidator.addValidation(“Billing_Number”,”numeric”);
frmvalidator.addValidation(“Billing_expMonth”,”dontselect=0″,”Please select Credit Card Expiration Month”);
frmvalidator.addValidation(“Billing_expYear”,”dontselect=0″,”Please select Credit Card Expiration Year”);
frmvalidator.addValidation(“Billing_CCV”,”req”,”Please enter your Credit Card CCV/CCV2 Security Code”);
frmvalidator.addValidation(“Billing_CCV”,”numeric”);

frmvalidator.addValidation(“Billing_FirstName”,”req”,”Please enter your Billing First Name”);
frmvalidator.addValidation(“Billing_FirstName”,”maxlen=250″);
frmvalidator.addValidation(“Billing_LastName”,”req”,”Please enter your Billing Last Name”);
frmvalidator.addValidation(“Billing_LastName”,”maxlen=250″);
frmvalidator.addValidation(“Billing_Address1″,”req”,”Please enter your Billing Address”);
frmvalidator.addValidation(“Billing_Address1″,”maxlen=250”);
frmvalidator.addValidation(“Billing_City”,”req”,”Please enter your Billing City”);
frmvalidator.addValidation(“Billing_State”,”dontselect=0″,”Please select your Billing State”);
frmvalidator.addValidation(“Billing_Zip”,”req”,”Please enter your Billing Zip Code”);
frmvalidator.addValidation(“Billing_Zip”,”numeric”);
}

frmvalidator.addValidation(“Shipping_FirstName”,”req”,”Please enter your Shipping First Name”);
frmvalidator.addValidation(“Shipping_FirstName”,”maxlen=250″);
frmvalidator.addValidation(“Shipping_LastName”,”req”,”Please enter your Shipping Last Name”);
frmvalidator.addValidation(“Shipping_LastName”,”maxlen=250″);
frmvalidator.addValidation(“Shipping_Address1″,”req”,”Please enter your Shipping Address”);
frmvalidator.addValidation(“Shipping_Address1″,”maxlen=250”);
frmvalidator.addValidation(“Shipping_City”,”req”,”Please enter your Shipping City”);
frmvalidator.addValidation(“Shipping_State”,”dontselect=0″,”Please select your Shipping State”);
frmvalidator.addValidation(“Shipping_Zip”,”req”,”Please enter your Shipping Zip Code”);
frmvalidator.addValidation(“Shipping_Zip”,”numeric”);

</script>
<script type=”text/javascript”>
<!–
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+”.location='”+selObj.options[selObj.selectedIndex].value+”‘”);
if (restore) selObj.selectedIndex=0;
}
//–>
</script>
[/CODE]

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @TiGGi spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...