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

190
Visualizações
My JavaScript querySelector is returning a null value when i try to access a form submission on the webpage

I am trying to use my Pig Latin generator on a local webpage. everything seems to work as intended, however, when i use the form to input a string, the debugging screen shows the queryselector as having returned null.

also, as a side note, the alert is sent every time I refresh the webpage. if you could also let me know how to fix/disable that I would appreciate it. thanks.

My html form element

<form onsubmit="translate(); return: false;">
    <input id="string" type="text">
    <input type="submit">
</form>

calling the .js file in the head

    <script src="pigLatin.js" defer></script>
</head>

my querySelector line

function translate() {
  let str = document.querySelector('#string').value;

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

HTML element has a attribute "translate" , same name with your function and make your function invisible. you could just rename your function or use it with a window. prefix.

function translate() {
  let str = document.querySelector('#string').value;
  console.log("strint value:", str);
}
<form onsubmit="console.log('translate type:', typeof translate); return false;">
    <input id="string" type="text">
    <input type="submit" value="not work">
</form>

<form onsubmit="window.translate(); return false;">
    <input id="string" type="text">
    <input type="submit" value="works">
</form>

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