0

I'm currently doing a project for my class and I really need help on this one. I have a text input in wich the user will have to enter his permanent code (1234567, 7654321...) But I would like to return the first character so that the user would only be able to enter numbers that are starting with either 1 or 2. if(1234567) = good / if(7654321) = error! My problem is that the charAt(0) thingy doesn't seem to work with inputs for me.

  const code = document.getElementById('user_code');
  const checkup = code.charAt(0);
  button.addEventListener('click', ()=>{
    console.log(checkup);

  })

Thank you for your help! I am not used to talk nor write in english so sorry for the mistakes!

I tried those things : document.getElementById('user_code').innerHTML; and document.getElementById('user_code').innerText; and console.log(checkup.ToString);

Pathou
  • 1
  • `code` is the _element_ - you want its _value_. Try `code.value.charAt(0)`. Or even `code.value[0]` (because a string is iterable). – Andy Nov 26 '22 at 15:00

0 Answers0