Textarea with value that can not change

0

So, I have a textarea like this:

<textarea id="mensagem" name="mensagem" type="text" style="width:400px; font-size:16px; height:100px; border-color:lightgray;" placeholder="Um texto qualquer" required> </textarea>

My intention is as follows: I'll be able to type in the textarea, but only to complement the message that will already be there. Can you do that?

    
asked by anonymous 27.06.2018 / 03:19

2 answers

0

If you intend to submit textarea content by clicking a button, you can do this as follows.

  

I will not submit the form to see the script running.

function myFunction() {
var fixo = document.getElementById("txtFixo").innerText;

var texto=document.getElementById("myTextarea").value;

document.getElementById("myTextarea").value = fixo + " " + texto;

document.getElementById("txtFixo").innerText="";
}
div.textarea-container {
   border: solid 1px #808080;
   overflow: auto;
   width: 400px;
   padding: 2px;
   font-family: Arial;
   font-size: 12px;
}

div.textarea-container textarea {
   font-family: Arial;
   font-size: 12px;
   overflow: auto;
   border: none;
   outline: none;
   width: 400px;
   height: 100px;
   margin: 0px;
   padding: 0px;
   resize: none;
}
<div class="textarea-container" onclick="document.getElementById('myTextarea').focus()">
    <div id="txtFixo">Textarea com value que não da pra mudar.<br>Qual é a cor do cavalo branco do Napoleão? </div>
    <textarea id="myTextarea" style="width:400px; font-size:16px; height:100px; border-color:lightgray;" placeholder="Responda aqui" required></textarea>
</div>

<button type="button"  onclick="myFunction()">Submit</button>
    
27.06.2018 / 05:28
-1
  

A simpler way to start everything can be this way

<textarea id="mensagem" name="mensagem" type="text" style="width:400px; font-size:16px; height:100px; border-color:lightgray;" required>Um Texto Fixo aqui </textarea>

In this way the text will already be deposited inside the textarea, so when the person clicks on the field, it will complement what you want in front of your sentence.

    
27.06.2018 / 04:48