Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

Credit card component with css custom properties and vanilla js

Kamil 120

@kamilp522

Desktop design screenshot for the Interactive card details form coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
2junior
View challenge

Design comparison


SolutionDesign

Solution retrospective


Hi everyone! After completing a few newbie projects, I've put my hands on this one and run into some problems:

Ad 1. I can't put maximum length on type number inputs in html, I've tried to do that with js but failed miserably, any ideas?

Ad 2. How to restrict input fields eg. in MM field how do I restrict it to only take inputs of 1 to 12? When using html max attribute I only get a text message and can still enter any number I want.

Community feedback

Eray 1,410

@ErayBarslan

Posted

Hey there, congrats on your solution!

  • Unfortunatelly maxlength doesn't work as expected with number inputs. I prefer to use type: text and when I need to call the input to JS I convert it like Number(input). If you wish to keep it as number though in JS you can create a function:
const maxChar = (el, max) => {
  if (el.value.length > max) {
    el.value = el.value.slice(0, max)
  }
}

<input
  ...
  type="number"
  onkeypress="maxChar(this, 16)"
  />

Also as for <label> elements, name should match with the input id like:

<label for="name">cardholder name</label>

<input id="name" />

Other than these not much I'd change. Happy coding :)

Marked as helpful

0

Kamil 120

@kamilp522

Posted

Hi, thanks for the feedback! :D I'll probably try to convert text into number by js which now seems so obvious, but hey, thats part of the learning process. Thanks again

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord