CARD HOLDER NAME HERE


MM / YY

Let's Use Javascript to Detect and Show which Credit Card is being entered. We're also going to use some CSS to "flip" the card over and reveal the back like we're in real life!

OUR PROBLEM

You're given the challenge of creating a new checkout form for your company. The credit card form is not performing well, so you need to make it perform better. What should your first step be? Change the submit button color and run an A/B test on that! You could also try out different headlines or use a sick graphic of someone entering their real CREDIT cards into payment processing systems - this will give users some sense trust when finalizing their purchase at checkout while adding new digital elements onto our pages which are sure worth exploring in more detail if we want our company's conversion rates to increase even further

Why You might need this

  • Use Javascript to detect the correct type of credit card
  • Simulate a real credit card
  • We can do this with a combination of Javascript & jQuery
  • This should be cross browser compatible and secure

ANSWER: Let's Use jQuery and CSS

Adding this to any modern checkout page will add extra authenticity in their experience. Why not use an innovative CSS transition that simulates entering your credit card information in person!

Let's start with the pseudo code here. First, we'll want to create the HTML form and a placeholder graphic to represent our credit card. Next we'll need to add a placeholder image for the back of the card that will "reveal" on focus. For the placeholder graphic we use a blank credit card. We use CSS to position the text where it should show up in a real life card. For the javascript we'll need to create 1 function to format all the form data and display it on the pretend credit card. We'll set up our variables like a c++ program.

You'll need to "GET" the card number value and use the jQuery .match function to check if the card is VISA or Mastercard. I use the keyup method to trigger our function everytime someone types in the form. We use .blur and .change methods on the other form inputs to format and trigger the display on the pretend card. The CSS below handles all the flips and z-indexing/ element positioning.

View Code Example Below:

What's Needed

  • jQuery CSS & Javascript
  • Include jQuery in the <head>
  • Images of Visa and Mastercard Credit Cards
  • .match() should have a clear understanding of this javascript method - match() on MOZ
  • We can do this with a combination of plain JS & HTML and CSS
  • This should be cross browser compatible and work on mobile devices
  • Some CSS transitions

The "trick" here is to show the credit card update as the user is typing in the form. This way they know the page is updating the display in realtime and no funky loaders are needed. This is a little more advanced of a script but once you master all the methods involved you can open this up for further customization.


Updated: Jan 2022


Feel free to share this Source Code and use on your personal Website Projects.
All scripts and snippets authored by https://www.andysotura.com