Skip to main content
Known Participant
December 12, 2007
Question

Activating validate on cfinput only when checkbox is selected

  • December 12, 2007
  • 1 reply
  • 423 views
I am designing a credit-card entry form hat automatically checks the validity of an entered credit-card number. Using cfinput validate="creditcard" works fine, but I cannot figure out a way (maybe using Javascript) to turn off validation if the user selects "Gift Card" from either a drop-down menu or a checkbox. If I use two boxes then ultimately the credit-card field box will be left empty - also causing problems for the validation of that field.

Any suggestions?

Thank you.
This topic has been closed for replies.

1 reply

Inspiring
December 13, 2007
Ok, here's a simple suggestion that might achieve what you're looking for:

Script the 'gift card' checkbox so that when it's unchecked, the credit card input displays and when it's checked, the cc field is hidden. In the js where you hide the cc field, update its value to 4111111111111111. It will then pass the validation check just fine. Then you can just clear the value if the gift card checkbox is unchecked.

Short-circuiting the auto-generated javascript validation would be a lot more complicated than simply supplying it with a value that passes validation.

Make sense?
Legend
December 21, 2007
quote:

Originally posted by: freakyAndFree
...update its value to 4111111111111111.
Unless the latest MX updated the creditcard validation logic, simply assigning a value of "0" passes the check, satisfies the required parameter and may be a little easier to work with during the action processing.