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

383
Visualizações
How to prevent line breaks in pre-filled input field from disappearing when extracting its output? (JS)

currently stuck on a problem when doing a JS project on creating an online mail application.

For each email, there would be a reply email button, which when clicked on, will run the reply_email function. As shown below, this function would use the compose_email function with the input fields for sender(pre-filled to be the one logged in), recipients, subject and body. For this reply_email function, it would pre-fill the recipients to be the sender of the previous email, and the sender to be you. For the body, it would put the body of the previous email underneath this reply email.

function reply_email(email) {
  // use the compose email template
  compose_email();

  // set the recipient of the reply email as the sender of the original email
  document.querySelector('#compose-recipients').value = email['sender'];
  
  // set the subject of the reply email as 'Re: ' and then the subject of the original email, if a 'Re: ' isn't already there
  if (email['subject'].split(" ", 1)[0] != "Re:") {
    document.querySelector('#compose-subject').value = `Re: ${email['subject']}`;
  } else {
    document.querySelector('#compose-subject').value = email['subject'];
  }

  // can pre-load the values ok, but when submit all the spacing and blank lines in between all disappear. how to fix?
  document.querySelector('#compose-body').value = `\n \n \n On ${email['timestamp']}, \n <${email['sender']}> wrote: \n      ${email['body']}`;

}

As seen in image_1, in the reply_email template, the body section looks ok, with the previous email being a few lines down. However, after successfully sending a reply, all the line spaces would all disappear in the view single email page, as shown in image_2.

enter image description here

enter image description here

Anyone has any idea what the problem may be? Currently quite stuck on this portion.

Any help would be greatly appreciated. Thank you!

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

0

Turns out when outputting the text value I used 'innerHTML' when it should have instead been 'innerText'.

Thanks to those who have spent the time reading this.

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