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

183
Visualizações
How can I display textarea client input on website without changing URL?

I am attempting to implement a feature on my website, where a user can input a comment into a textarea and have it display the comment, below the comment box. For backend I am using bottle. At the moment, bottle is recognizing the input, and when input is submitted, a new url loads displaying only the input of the textarea. When submitted, I need the textarea input to be displayed below the textarea box, without changing the webpage.

Here is HTML textarea input

<div>
  <p>
    Add a comment
  </p> 

  <form action="/comment" method="post">
  <textarea name="text"></textarea>
  <input type="submit" value="Submit">
  </form>
  
</div>

Bottle in main.py

@route('/comment', method = 'POST')
def submit():
  com = request.forms.get('text')
  print('Printing comment...')
  print(com)
  return com

index.js, (i'm not sure how to integrate this function)

function loadCom () {

  var xhttp2 = new XMLHttpRequest();
    xhttp2.onreadystatechange = function(){
        if (this.readyState === 4 && this.status === 200){
            console.log(this.response);

            document.getElementById("dcom").innerHTML = this.response;  
        }
    };

  xhttp2.open("GET", "/comment");
  xhttp2.send();

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

0

Call loadCom() from an event listener.

document.querySelector("form").addEventListener("submit", e => {
    e.preventDefault(); // prevent reloading the page
    loadCom();
});

loadCom() needs to use the POST method to send the value of the textarea to the controller.

function loadCom () {

  var xhttp2 = new XMLHttpRequest();
    xhttp2.onreadystatechange = function(){
        if (this.readyState === 4 && this.status === 200){
            console.log(this.response);

            document.getElementById("dcom").innerHTML = this.response;  
        }
    };

  xhttp2.open("POST", "/comment");
  xhttp2.send('text=' + encodeURIComponent(document.querySelector('[name="text"]').value);

  return false
}
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