I will publish my comment as a response, already suitable for com outros campos
etc...
Just make use of concatenation.
Concatenation
We can understand concatenation to be the joining of two strings (phrases or words). The operator for concatenating is the plus sign +
.
function submitted() {
var formValue = '<div>'+ document.getElementsByName("texto")[0].value +'</div>';
formValue += '<script>'+ document.getElementsByName("texto")[1].value +'<\/script>';
formValue += '<style>'+ document.getElementsByName("texto")[2].value +'</style>';
document.getElementsByName("texto")[3].value = formValue;
return false;
}
<form onsubmit="return submitted()">
Campo 1:<br><input type="text" name="texto"><br>
Campo 2:<br><input type="text" name="texto"><br>
Campo 3:<br><input type="text" name="texto"><br>
<input type="submit" value="Enviar"><br><br>
Pós texto:<br><input type="text" name="texto">
</form>
To textarea
, for each to stay on a separate line, and not to send blank or null fields.
linha separada
just add \n
(new line) at the location you want to break the line.
para não enviar campos em branco
use the method trim()
The Trim() method removes unnecessary spaces declared at the beginning and/or end of a string.
Compatibility between browsers
function submitted() {
var texto0= (document.getElementsByName("texto")[0].value).trim();
var texto1= (document.getElementsByName("texto")[1].value).trim();
var texto2= (document.getElementsByName("texto")[2].value).trim();
if(texto0!=""){
texto0= '<div>'+ texto0 +'</div>\n';
}
if(texto1!=""){
texto1= '<script>'+ texto1 +'<\/script>\n';
}
if(texto2!=""){
texto2= '<span>'+ texto2 +'<\/span>\n';
}
var formValue = texto0 + texto1 + texto2;
document.getElementsByName("texto")[3].value = formValue;
return false;
}
<form onsubmit="return submitted()">
Campo 1:<br><input type="text" name="texto"><br>
Campo 2:<br><input type="text" name="texto"><br>
Campo 3:<br><input type="text" name="texto"><br>
<input type="submit" value="Enviar"><br><br>
<textarea name="texto" style="height:200px"></textarea
</form>
In the closing tags </script>
must escape the bar /
with a counter \
,that is to say <\/script>
can also use as follows: </scr'+'ipt>
formValue += '<script>'+ document.getElementsByName("texto")[1].value +'</scr'+'ipt>\n';
when it splits into two strings and concatenates, it will not interfere with the rendering engine
Your question was not very clear, you want to show the result on another page is this?
– LeAndrade
I rephrased the question
– Mark Vaaz
But if you do not want to send the form, because it is giving a false Return, pq take the information from a form?
– LeAndrade
formValue = "<div>"+(Document.getElementsByName("text")[0].value)+"</div>";
– user60252
Hi friend! Why keeps alternating the marking of a response to another?
– Sam
Hi sorry I didn’t realize I could only accept 1 as the right answer.
– Mark Vaaz