/    Sign up×
Community /Pin to ProfileBookmark

Form Validation

Hi all…

I am using form validator ([url]http://www.javascript-coder.com/html-form/javascript-form-validation.phtml[/url]) and it works just fine. My problem is that I would like to turn on/off validation for some of the fields if another field is not blank. The validation script is located on the bottom of the page and this is what I got:

[CODE]<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”);
}[/CODE]

then i have the rest of the field validations that should run at all times.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@AmphidamasApr 27.2009 — Hi all...

I am using form validator (http://www.javascript-coder.com/html-form/javascript-form-validation.phtml) and it works just fine. My problem is that I would like to turn on/off validation for some of the fields if another field is not blank. The validation script is located on the bottom of the page and this is what I got:

[CODE]<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");
}[/CODE]

then i have the rest of the field validations that should run at all times.[/QUOTE]


Those are just the validation checks that you have added to the form validator. To edit what you're asking you would have to edit the code in the provided .js file, and correct me if I'm wrong, but the provided .js file has over 1000 lines of JavaScript code... ? You would have to specify what it is exactly that you wish to be changed for anybody to help I guess.

Regards,

Amph.
Copy linkTweet thisAlerts:
@TiGGiauthorApr 27.2009 — Exactly, so what I am trying to do is disable validation checks for those fields if user types in something in the Finance_Code field. I really don't want to change anything in the js file.
Copy linkTweet thisAlerts:
@AmphidamasApr 27.2009 — Did you write this code?

<i>
</i>if (document.myForm.Finance_Code.value == "")


Would it be possible for you to attach the file containing the above code, and the external .js file to your next post also, please.

Regards,

Amph.
Copy linkTweet thisAlerts:
@TiGGiauthorApr 27.2009 — Yes I wrote that code. I would've sworn that it worked last week but not I am not even sure.

I got both the html and the js files included.

[upl-file uuid=e738b06c-2725-4821-88df-b92b666b5b55 size=6kB]shipping_billing.html.txt[/upl-file]

[upl-file uuid=bba77747-a006-454c-812d-b4e3c724e1e8 size=19kB]gen_validatorv31.js.txt[/upl-file]
Copy linkTweet thisAlerts:
@TiGGiauthorApr 28.2009 — Anyone?
Copy linkTweet thisAlerts:
@TiGGiauthorApr 30.2009 — bump
×

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 5.19,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...