HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<h1>Choose Payment</h1>
<p id="choosen-paymenttype">Credit Card</p>
<ul class="payment-types">
<li class="paymenttype pp unselected-left">
<div class="box">
<header>
<div class="card" id="pp-card">
<div class="flipper">
<div class="front">
<div class="shine"></div>
<div class="shadow"></div>
<div class="card-bg">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/pp-front-bg.png" />
</div>
</div>
</div>
</div>
</header>
<form>
<div class="form-content">
<p><strong>About</strong></p>
<p>This is a basic concept for a payment, checkout process. The user can select between the different payment types, each type has a seperate form to fill in the required data for the transaction. What I tried to provide:</p>
<ul>
<li>A quick and easy way to fill the required form fields.</li>
<li>Mobile friendly keyboard display</li>
<li>Disabling auto-correction and spellcheck for names</li>
<li>Avoid dropdown fields for a better UX.</li>
</ul>
</div>
</form>
</div>
</li>
<li class="paymenttype selected cc">
<div class="box">
<header>
<div class="card" id="cc-card">
<div class="flipper">
<div class="front">
<div class="shine"></div>
<div class="shadow"></div>
<div class="card-bg">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/cc-front-bg.png" />
</div>
<div class="card-content">
<div class="credit-card-type"></div>
<div class="card-number">
<span>1234 1234 1234 1234</span>
<span>1234 1234 1234 1234</span>
</div>
<div class="card-holder">
<em>Card holder</em>
<span>Your Name</span>
<span>Your Name</span>
</div>
<div class="validuntil">
<em>Expire</em>
<div class="e-month">
<span>
MM
</span>
<span>
MM
</span>
</div>
<div class="e-divider">
<span>
/
</span>
<span>
/
</span>
</div>
<div class="e-year">
<span>
YY
</span>
<span>
YY
</span>
</div>
</div>
</div>
</div>
<div class="back">
<div class="shine"></div>
<div class="shadow"></div>
<div class="card-bg">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/cc-back-bg-new.png" />
</div>
<div class="ccv">
<em>CCV Number</em>
<strong></strong>
</div>
<div class="card-content">
<div class="card-number">
<span>4111 1111 1111 1111</span>
<span>4111 1111 1111 1111</span>
</div>
<div class="card-holder">
<span>Your Name</span>
<span>Your Name</span>
</div>
<div class="validuntil">
<span>
<strong class="e-month">MM</strong> / <strong class="e-year">YY</strong>
</span>
<span>
<strong class="e-month">MM</strong> /
<strong class="e-year">YY</strong>
</span>
</div>
</div>
</div>
</div>
</div>
</header>
<form>
<div class="form-content">
<div class="field">
<input type="tel" id="cardnumber" maxlength="20" />
<span class="focus-bar"></span>
<label for="cardnumber">Card number</label>
</div>
<div class="field">
<input type="text" autocorrect="off" spellcheck="false" id="cardholder" maxlength="25" />
<span class="focus-bar"></span>
<label for="cardholder">Card holder (Name on card)</label>
</div>
<div class="field-group">
<div class="col-50">
<label for="expires-month">Expire (Valid until)</label>
<div class="field expire-date">
<div>
<input type="tel" id="expires-month" placeholder="MM" allowed-pattern="[0-9]" maxlength="2">
<span class="focus-bar"></span>
</div>
<div class="divider">/</div>
<div>
<input type="tel" id="expires-year" placeholder="YY" allowed-pattern="[0-9]" maxlength="2">
<span class="focus-bar"></span>
</div>
</div>
</div>
<div class="col-50">
<div class="field ccv">
<input type="tel" id="ccv" autocomplete="off" maxlength="3" />
<span class="focus-bar"></span>
<label for="ccv">CCV</label>
</div>
</div>
</div>
<button><span>Submit</span></button>
</div>
</form>
</div>
</li>
<li class="paymenttype ec unselected-right">
<div class="box">
<header>
<div class="card" id="ec-card">
<div class="flipper">
<div class="front">
<div class="shine"></div>
<div class="shadow"></div>
<div class="card-bg">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/ec-front-bg.png" />
</div>
</div>
</div>
</div>
</header>
<form>
<div class="form-content">
<p><strong>This is just a demo</strong></p>
<p>It is neither complete, nor optimized code. In CSS it is playing around with text-shadow, transformations, transitions and a few animations. Some quick coded JavaScript to handle the required interactions. Anyway it might be an inspiration or a starting point.</p>
<p>Made with ❤ by webandapp.fr</p>
</div>
</form>
</div>
</li>
</ul>
html, body {
min-height: 100%;
margin: 0;
padding: 0;
}
html {
box-sizing: border-box;
}
*, *:before, *:after {
box-sizing: inherit;
}
body {
font-family: 'Open sans', sans-serif;
padding-bottom: 50px;
&:after {
content:'';
position: fixed;
left: 0;
top: 0;
z-index: -2;
opacity: .2;
width: 100%;
height: 100%;
background-attachment: fixed;
background-size: cover;
background-repeat: no-repeat;
}
&:before {
content:'';
position: fixed;
left: 0;
top: 0;
z-index: -1;
opacity: .2;
width: 100%;
height: 100%;
background: linear-gradient(180deg, rgba(0,0,0,0) 0%, #000 100%);
}
&.cc-bg {
background: linear-gradient(45deg, #cb60b3 0%,#71117d 50%,#39296b 100%);
&:after {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/bg-cc-form.jpg);
}
}
&.ec-bg {
background: linear-gradient(45deg,#a3caeb 0%,#528ec4 50%,#01578a 100%);
&:after {
background-image:url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/world.png);
opacity: .1;
background-size: auto;
background-position: center center;
}
}
&.pp-bg {
background: linear-gradient(45deg, #fff 0%,#cfcfcf 80%,#aaa 100%);
&:after {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/bg-pp.png);
background-repeat: repeat;
background-size: auto;
opacity: .7;
}
h1, #choosen-paymenttype {
color: #000;
}
}
}
h1 {
font-weight: 100;
color: #fff;
text-transform: uppercase;
letter-spacing: 1;
text-align: center;
font-size: 16px;
margin: 20px 0 5px 0;
}
#choosen-paymenttype {
text-align: center;
color: #fff;
margin: 0;
font-size: 12px;
}
ul.payment-types {
list-style-type: none;
margin: 0;
padding: 0;
li.paymenttype {
margin-bottom: 30px;
}
}
.unselected-left,
.unselected-right {
&:hover .shadow {
box-shadow: 0 25px 40px rgba(14,21,47,0.4), 0 8px 20px rgba(14,21,47,0.4);
}
}
.selected form {
max-height: 800px !important;
opacity: 1;
}
@media only screen and (min-width: 1080px) {
ul.payment-types {
width: 1040px;
min-height: 600px;
margin: 0 auto;
position: relative;
-webkit-transform-origin: 0 0;
transform-origin: 0 0;
}
li.paymenttype {
position: absolute;
width: 300px;
transition: transform .5s ease-in;
&.selected {
width: 440px;
}
}
.unselected-left,
.unselected-right {
.box {
transform: scale(.75);
}
.card {
cursor: pointer;
}
}
.cc.selected {
transform: translate3d(300px,0,0);
}
.cc.unselected-left {
transform: translate3d(0,0,0);
}
.cc.unselected-right {
transform: translate3d(740px,0,0);
}
.pp.selected {
transform: translate3d(300px,0,0);
}
.pp.unselected-left {
transform: translate3d(0,0,0);
}
.pp.unselected-right {
transform: translate3d(740px,0,0);
}
.ec.selected {
transform: translateX(300px);
}
.ec.unselected-right {
transform: translate3d(740px,0,0);
}
.ec.unselected-left {
transform: translate3d(0,0,0);
}
}
header {
position: relative;
height: 200px;
}
.card {
position: absolute;
left: 50%;
transform: translateX(-50%);
top: 50px;
width: 300px;
height: 188px;
border-radius: 16px;
perspective: 1000px;
transition: transform .5s ease-in;
z-index: 5;
.shine {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 16px;
background: linear-gradient(135deg, rgba(255,255,255,.25) 0%,rgba(255,255,255,0) 60%);
z-index: 5;
}
.card-bg {
z-index: 2;
}
.shadow {
position: absolute;
top: 0;
left: 5%;
width: 90%;
height: 100%;
transition: all 0.2s ease-out;
box-shadow: 0 8px 30px rgba(14,21,47,0.6);
z-index: 1;
border-radius: 16px;
}
.flipper {
transition: 0.75s;
transform-style: preserve-3d;
position: relative;
width: 300px;
height: 188px;
}
&.flipped .flipper {
transform: rotateY(180deg);
}
.front,
.back,
.card-bg,
.card-content {
width: 100%;
height: 100%;
position: absolute;
left: 0;
top: 0;
position: absolute;
}
.card-content {
text-shadow: -1px -1px 0px rgba(255,255,255,0.3), 1px 1px 0px rgba(0,0,0,0.5);
color: #b0b0b0;
font-family: 'Droid Serif', serif;
z-index: 4;
span {
left: 0;
top: 0;
display: block;
position: absolute;
width: 100%;
overflow: hidden;
color: #7a1a86;
padding-left: 2px;
white-space: nowrap;
}
span + span {
color: #a545b1;
height: 7px;
overflow: hidden;
}
strong {
font-weight: normal;
}
em {
text-transform: uppercase;
position: absolute;
font-style: normal;
font-size: 9px !important;
text-shadow: none;
font-family: Open sans, sans-serif;
color: rgba(255,255,255,.6);
}
.glow {
animation: glow .5s;
}
}
.front,
.back {
backface-visibility: hidden;
box-shadow: 0 4px 8px rgba(10,10,10,0.25);
border-radius: 16px;
}
.front {
z-index: 2;
transform: rotateY(0deg);
}
.back {
z-index: 1;
transform: rotateY(180deg);
.card-content {
opacity: .7;
text-shadow: -1px -1px 0px rgba(0,0,0,0.5), 1px 1px 0px rgba(255,255,255,0.3);
transform: rotateY(180deg);
span + span {
color: transparent;
}
}
}
.ccv {
position: absolute;
right: 15px;
height: 20px;
width: 30px;
top: 52px;
font-size: 14px;
strong {
font-weight: normal;
font-style: italic;
}
em {
position: absolute;
white-space: nowrap;
font-size: 8px;
left: -60px;
}
}
.credit-card-type {
position: absolute;
right: 20px;
top: 20px;
background-color: rgba(255,255,255,.4);
width: 50px;
height: 30px;
border-style: solid;
border-color: rgba(255,255,255,0);
border-width: 2px;
background-repeat: no-repeat;
background-size: contain;
background-position: center center;
&.amex {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/amex.svg);
background-color: #fff;
}
&.visa {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/visa.svg);
background-color: #fff;
}
&.mastercard {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/513985/mastercard.svg);
background-color: #fff;
}
}
.card-number {
position: absolute;
width: 240px;
top: 100px;
left: 30px;
font-size: 21px;
height: 21px;
font-family: courier;
text-align: justify;
}
.card-holder {
em {
top: -16px;
}
text-transform: uppercase;
position: absolute;
width: 240px;
top: 160px;
left: 20px;
font-size: 14px;
font-weight: 100;
height: 30px;
span {
letter-spacing: 1px;
}
span + span {
height: 4px;
}
}
.validuntil {
em {
top: 3px;
left: -36px;
}
font-family: courier;
position: absolute;
top: 128px;
left: 150px;
font-size: 16px;
height: 16px;
width: 120px;
white-space: nowrap;
font-family: courier;
.e-month,
.e-divider,
.e-year {
letter-spacing: 1px;
display: inline-block;
position: relative;
float: left;
margin: 0 1px;
span {
position: relative;
}
span + span {
position: absolute;
height: 5px;
}
}
}
}
.card-bg {
img {
border-radius: 12px;
}
}
form {
margin: 0 auto;
max-width: 400px;
min-width: 320px;
border-top: 0;
overflow: hidden;
max-height: 0;
opacity: 0;
transition: opacity, max-height .5s ease-in;
ul {
list-style-type: square;
margin: 0;
padding: 0 40px 0 20px;
}
p,li {
line-height: 1.3;
font-size: 14px;
}
li {
margin-bottom: 12px;
}
.form-content {
border: 1px solid #ccc;
padding: 70px 20px 20px 20px;
background: #e4e4e4;
min-height: 400px;
}
label {
display: block;
margin-bottom: 5px;
font-size: 12px;
line-height: 1;
text-transform: uppercase;
color: #666;
position: relative;
}
.field label {
top: -50px;
}
.field-group,
.field {
margin-bottom: 20px;
position: relative;
}
.field {
padding-top: 17px;
}
.field-group:after,
.field-group:before {
content: '';
display: table;
clear: both;
}
.focus-bar {
display: block;
width: 100%;
height: 2px;
margin-top: -1px;
z-index: 2;
pointer-events: none;
position: relative;
&:before,
&:after {
content: '';
height: 2px;
width: 0;
bottom: 1px;
position: absolute;
background: rgb(225, 157, 60);
transition: 0.2s ease all;
}
&:before {
left:50%;
}
&:after {
right:50%;
}
}
input {
width: 100%;
padding: 5px;
font-size: 16px;
border: 1px solid #CCC;
position: relative;
height: 32px;
&:focus {
outline: none;
}
&:focus + .focus-bar:before,
&:focus + .focus-bar:after {
width: 50%;
}
&:focus + .focus-bar + label,
&:focus + .focus-bar + label {
color: #ccc;
}
}
.expire-date {
padding-top: 0;
input {
width: 50px;
}
div {
float: left;
}
.divider {
padding: 0 5px;
line-height: 32px;
color: #ccc;
user-select: none;
}
}
.ccv {
width: 80px;
float: right;
}
::selection {
background: rgba(253, 218, 134,.6);
}
::-moz-selection {
background: rgba(253, 218, 134,.6);
}
button {
position: relative;
overflow: hidden;
padding: 10px;
display: block;
width: 80%;
background: linear-gradient(rgb(253, 218, 134) 0px, rgb(225, 157, 60) 100%);
color: #fff;
font-size: 14px;
border: 1px solid rgb(225, 157, 60);
box-shadow: 0 1px 4px rgba(0, 0, 0, .6);
border-radius: 2px;
margin: -20px auto 10px auto;
transition: 0.75s ease border-color;
span {
position: relative;
z-index: 2;
}
&:after {
transform: translate(-50%,-50%);
content: '';
background: rgb(225, 157, 60);
width: 0px;
height: 0px;
position: absolute;
top: 50%;
left: 50%;
border-radius: 50%;
}
&:hover {
background: rgb(225, 157, 60);
}
&:focus {
outline: none;
border-color: rgb(177, 106, 2);
}
&:focus:after {
animation: anim-out 0.75s;
animation-fill-mode: forwards;
}
}
}
.col-50 {
width: 50%;
float: left;
}
@keyframes glow {
0% {
text-shadow: -1px -1px 0px rgba(255,255,255,0.3), 1px 1px 0px rgba(0,0,0,0.5);
}
70% {
color: rgba(255,255,255,.4);
text-shadow: -1px 1px 8px #ffc, 1px -1px 8px rgba(255,255,255,.6);
}
100% {
text-shadow: -1px -1px 0px rgba(255,255,255,0.3), 1px 1px 0px rgba(0,0,0,0.5);
}
}
@keyframes anim-out {
0% {
width: 0%;
height: 0px;
}
100% {
width: 200%;
height: 300px;
}
}
(function payment() {
var d = document,
body = d.getElementsByTagName('body')[0],
html = d.getElementsByTagName('html')[0],
ppForm = d.getElementsByTagName('form')[0],
ccForm = d.getElementsByTagName('form')[1],
ecForm = d.getElementsByTagName('form')[2],
cCard = d.querySelector('#cc-card'),
pCard = d.querySelector('#pp-card'),
eCard = d.querySelector('#ec-card'),
info = d.querySelector('#choosen-paymenttype'),
ccNumber = ccForm.querySelector('#cardnumber'),
cNumber = d.querySelectorAll('.card-number'),
ccName = ccForm.querySelector('#cardholder'),
cName = d.querySelectorAll('.card-holder'),
ccMonth = ccForm.querySelector('#expires-month'),
cMonth = d.querySelectorAll('.e-month'),
ccYear = ccForm.querySelector('#expires-year'),
cYear = d.querySelectorAll('.e-year'),
ccCCV = ccForm.querySelector('#ccv'),
cCCV = d.querySelector('.ccv strong'),
ccCard = d.querySelectorAll('.credit-card-type'),
defaultNumber = cNumber[0].getElementsByTagName('span')[0].innerHTML,
defaultName = cName[0].getElementsByTagName('span')[0].innerHTML;
init();
function init() {
var cardType, cardNumber, cardName, cardCCV;
body.className = 'cc-bg';
function switchPos(elm) {
if (elm.classList.contains('selected')) {
if (elm.getElementsByTagName('input').length) {
elm.getElementsByTagName('input')[0].focus();
}
return;
}
var selected = d.querySelector('.selected');
if (elm.classList.contains('unselected-left')) {
selected.classList.remove('selected');
selected.classList.add('unselected-left');
elm.classList.add('selected');
elm.classList.remove('unselected-left');
if (window.matchMedia("(max-width: 1039px)").matches) {
setTimeout(function() {elm.scrollIntoView();}, 500);
}
} else if (elm.classList.contains('unselected-right')) {
selected.classList.remove('selected');
selected.classList.add('unselected-right');
elm.classList.add('selected');
elm.classList.remove('unselected-right');
if (window.matchMedia("(max-width: 1039px)").matches) {
setTimeout(function() {elm.scrollIntoView();}, 500);
}
}
}
addEvent(pCard,'click',function() {
switchPos(d.querySelector('.paymenttype.pp'));
body.className = 'pp-bg';
info.innerHTML = 'PayPal';
});
addEvent(cCard,'click',function() {
switchPos(d.querySelector('.paymenttype.cc'));
body.className = 'cc-bg';
info.innerHTML = 'Credit Card';
});
addEvent(eCard,'click',function() {
switchPos(d.querySelector('.paymenttype.ec'));
body.className = 'ec-bg';
info.innerHTML = 'Bank account';
});
addEvent(ccNumber, 'focus', function() {
cNumber[0].classList.add('glow');
});
addEvent(ccNumber, 'blur', function() {
cNumber[0].classList.remove('glow');
});
addEvent(ccName, 'focus', function() {
cName[0].classList.add('glow');
});
addEvent(ccName, 'blur', function() {
cName[0].classList.remove('glow');
});
addEvent(ccMonth, 'focus', function() {
cMonth[0].classList.add('glow');
});
addEvent(ccMonth, 'blur', function() {
cMonth[0].classList.remove('glow');
});
addEvent(ccYear, 'focus', function() {
cYear[0].classList.add('glow');
});
addEvent(ccYear, 'blur', function() {
cYear[0].classList.remove('glow');
});
addEvent(ccCCV, 'focus', function() {
cCard.classList.add('flipped');
});
addEvent(ccCCV, 'blur', function() {
cCard.classList.remove('flipped');
});
addEvent(ccNumber, 'keyup', function() {
cardNumber = this.value.replace(/[^0-9\s]/g,'');
if (!!this.value.match(/[^0-9\s]/g)) {
this.value = cardNumber;
}
cardType = getCardType(cardNumber.replace(/\s/g,''));
switch(cardType) {
case 'amex':
parts = numSplit(cardNumber.replace(/\s/g,''), [4,6,5]);
ccCard[0].className = 'credit-card-type amex';
break;
case 'mastercard':
parts = numSplit(cardNumber.replace(/\s/g,''), [4,4,4,4]);
ccCard[0].className = 'credit-card-type mastercard';
break;
case 'visa':
parts = numSplit(cardNumber.replace(/\s/g,''), [4,4,4,4]);
ccCard[0].className = 'credit-card-type visa';
break;
default:
parts = cardNumber.split(' ');
ccCard[0].className = 'credit-card-type';
}
cardNumber = parts.join(' ');
if (cardNumber != this.value) {
this.value = cardNumber;
}
if (!cardNumber) {
cardNumber = defaultNumber;
}
syncText( cNumber, cardNumber);
});
addEvent(ccName, 'keyup', function() {
cardName = this.value.replace(/[^a-zA-Z-\.\s]/g,'');
if (cardName != this.value) {
this.value = cardName;
}
if (!cardName) {
cardName = defaultName;
}
syncText( cName, cardName);
});
addEvent(ccMonth, 'keyup', function(ev) {
ev = ev || window.event;
var month = this.value.replace(/[^0-9]/g,'');
if(ev.keyCode == 38) {
if(!month) {month = 0;}
month = parseInt(month);
month++;
if(month < 10) {
month = '0'+month;
}
}
if(ev.keyCode == 40) {
if(!month) {month = 13;}
month = parseInt(month);
month--;
if(month == 0) { month = 1;}
if(month < 10) {
month = '0'+month;
}
}
if( parseInt(month) > 12) {
month = 12;
}
if( parseInt(month) < 1 && month != 0) {
month = '01';
}
if(month == '00') {
month = '01';
}
if (month != this.value) {
this.value = month;
}
if(month.toString().length == 2) {
syncText( cMonth, month);
}
});
addEvent(ccYear, 'keyup', function(ev) {
ev = ev || window.event;
var currentYear = new Date().getFullYear().toString().substr(2,2),
year = this.value.replace(/[^0-9]/g,'');
if(ev.keyCode == 38) {
if(!year) {year = currentYear;}
year = parseInt(year);
year++;
if(year < 10) {
year = '0'+year;
}
}
if(ev.keyCode == 40) {
if(!year) {year = parseInt(currentYear) + 5;}
year = parseInt(year);
year--;
if(year < 10) {
year = '0'+year;
}
}
if( year.toString().length == 2 && parseInt(year) < currentYear) {
year = currentYear;
}
if (year != this.value) {
this.value = year;
}
if (year > (parseInt(currentYear) + 5)) {
year = (parseInt(currentYear) + 5);
this.value = year;
}
if(year.toString().length == 2) {
syncText( cYear, year);
}
});
addEvent(ccCCV, 'keyup', function() {
cardCCV = this.value.replace(/[^0-9\s]/g,'');
if (cardCCV != this.value) {
this.value = cardCCV;
}
cCCV.innerHTML = cardCCV;
});
}
function syncText( elCol, text ) {
var collection;
for(var j=0; j < elCol.length; j++) {
collection = elCol[j].querySelectorAll('span');
if (!collection.length) {
elCol[j].innerHTML = text;
} else {
for(var i=0; i < collection.length; i++) {
collection[i].innerHTML = text;
}
}
}
}
function numSplit(number, indexes) {
var tempArr = number.split(''),
parts = [];
for (var i=0, l = indexes.length; i < l; i++) {
if (tempArr.length) {
parts.push(tempArr.splice(0,indexes[i]).join(''));
}
}
return parts;
}
function getCardType(number) {
var re;
// Mastercard
re = new RegExp("^5[1-5]");
if (number.match(re) != null) {
return "mastercard";
}
// AMEX
re = new RegExp("^3[47]");
if (number.match(re) != null) {
return "amex";
}
// visa
var re = new RegExp("^4");
if (number.match(re) != null) {
return "visa";
}
return "";
}
function addEvent(elem, event, func) {
elem.addEventListener(event,func);
}
})();
Also see: Tab Triggers