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

129
Visualizações
How to pass data from HTML to onClick js function?

I want to send data to my recommend.js function from recommend.html

words_to_highlight is an array datatype

I am initializing and passing the function from main.py using FLASK

recommend.js

function highlightText(words_to_highlight) {
    console.log('button pressed');
    console.log(words_to_highlight);
}

recommend.html

<button 
    class="display-keywords" 
    onclick="highlightText({{words_to_highlight}})"
>
    Display keywords
</button>

main.py

@app.route("/recommend",methods=["POST"])
def recommend():
    words_to_highlight = [//some_data]
    .
    .
    .
    return render_template('recommend.html',words_to_highlight=words_to_highlight)

from the html file:

onclick="highlightText({{words_to_highlight}})"

this line does not send the variable words_to_highlight to my js file as the console.log() in js prints nothing to my console

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

0

You only need to make few corrections

function clickHandler(data){
  console.log(data) //This will log the data from html button
}
<button onclick="clickHandler('This is the data I want to pass')">click me</button>

applying that to your question now:

function highlightText(words_to_highlight) {
    console.log('button pressed');
    console.log(words_to_highlight);
}
<button 
    class="display-keywords" 
    onclick="highlightText('{{words_to_highlight}}')"
>
    Display keywords
</button>

Note, if the data you want to pass is not a string you need to pass it to the data type in your javascript.

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