Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

262
Visualizações
How to make Javascript work in my EJS file?

I have been trying to figure out this prob of mine for a while now. Please see my code below. I want to compare my password and confirm my password. If it is not equal, then I want my button to be disabled. Then if it matched, then I want the button to be enabled. I'm using ejs template, so it's hard for me to put js inside. I am just a beginner. like this

javascript code for disabled and enabled button

 <%- include('partials/header') %>


<%function check_pass() {%>
 <% if (document.getElementById('password').value == document.getElementById('conpassword').value) {%>
    <%  document.getElementById('submit').disabled = false;%>
  <% }else {%>
     <% document.getElementById('submit').disabled = true;%>
  <% }%>
 <% }%>


  <div class="login-page">
    <form autocomplete="off" action="/register" method="POST">
      <h1> Sign Up</h1>
      <label for="lastname"> Last Name </label>
      <input autocomplete="off" type="text" name="lastname" />

      <label for="firstname"> First Name </label>
      <input autocomplete="off" type="text" name="firstname" />

      <label for="email"> Email </label>
      <input autocomplete="off" type="email" name="username" />

    
      <label for="password"> Password </label>
      <input name="password" id="password" type="password" onchange='check_pass()'/>

      <label for="password"> Confirm Password </label>
      <input name="conpassword" id="conpassword" type="password"onchange='check_pass()' />

      <button type="submit" class="submit" id="submit" disabled>>Sign up</button>


    </form>
 
  </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Remove <% your script %> tag from your script and wrap in tag script HTML, it's like writing in HTML format. For more information (tags EJS) see here: documentation.

<script>
function check_pass() {
 if (document.getElementById('password').value == document.getElementById('conpassword').value) {
      document.getElementById('submit').disabled = false;
     }else {
     document.getElementById('submit').disabled = true;
     }
}
check_pass();
</script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda