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

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

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 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