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

194
Views
I'm having trouble getting a button with onclick method that calls a js function to work

The basic premise of this app is like a radio that saves stations to certain channels to be recalled when clicked. I keep getting the index.html:111 Uncaught ReferenceError: saveOne is not defined at HTMLButtonElement.onclick (index.html:111) error in the console and also when I mouse over the function in my VSCode i get this error: 'saveOne' is declared but its value is never read.ts(6133)

I've looked everywhere for a while now and can't find any solution or clear explanation as to why it's not working.

Thanks!

//HTML// sorry I'm new to stack overflow ::facepalm:: I assure you the html is accurate, but I don't understand how to get it to work since im a stack overflow noob.

button onclick="" value="90.1" type="button" id="channel1" class="btn btn-secondary">One /button>

button type="button" onclick="saveOne()" id="save1" class="btn btn-dark save_btns">Save1 /button>

// JS FILE //

let channel1 = document.getElementById("channel1").value

function saveOne(){
    let saveChnl1 = current_station.innerHTML
    channel1 = saveChnl1
    // console.log(channel1) //100.3
    return channel1
    
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

OK there are so many things wrong with your question so I'll help you out.

Firstly, your html is completely invalid as it is missing correct open and close brackets.

button onclick="" value="90.1" type="button" id="channel1" class="btn btn-secondary">One /button>

button type="button" onclick="saveOne()" id="save1" class="btn btn-dark save_btns">Save1 /button>

Should be

<button value="90.1" type="button" id="channel1" class="btn btn-secondary">One</button>

<button type="button" onclick="saveOne()" id="save1" class="btn btn-dark save_btns">Save1</button>

Secondly, if you import your script correctly, you wont get any not defined errors.

Make sure that in your html head tag, you have a script tag with a src attribute like so:

<script src="script.js"></script>

and make sure that the path is correct. For information about html pathing, see HTML File Paths

Lastly, the javascript you provided wasn't valid either, but I'll assume that it uses some kind of global reference.

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!