Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda