Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!