0

Unsolve (Get All Input Element Value)

https://code.sololearn.com/WjA29qnwF6Lr/?ref=app I play with the html tag, but there are constraints that make me confused when taking value from an element. And I want all the values ​​to be drawn down (using <br>). Please help resolved.

6th Jan 2018, 5:40 AM
Muhammad Amin
Muhammad Amin - avatar
2 Réponses
+ 5
First you need to change your loop ending condition from 'i<=gen.length' to 'i<gen.length' as indexes start from zero, last item index of an array is length-1... Next, you need to update the textarea value instead of change it at each loop iteration with either: document.getElementById("teks").value = ""; // initialize the textarea value with empty content for (i=0; i<gen.length; i++) { document.getElementById("teks").value += gen[i].value + "<br>"; // a = a + b shortcut is a += b } ... or: var text = ""; // initialize a temp var for (i=0; i<=gen.length; i++) { text += gen[i].value + "<br>"; // concatenate all values in one } document.getElementById("teks").value = text; // update the value of textarea only once Last and anyway, textarea value doesn't support htm content, so to display real line-break inside them, you need to use the "\n" new line ascii escaped char instead the html <br> tag, unless you want to display html tags as is (source code)... (and to prevent tag characters to be treated as html tags in html content and be displayed as source code, you need to replace the '<', and at least the '&' html special meaning char by html entities '&lt;' and '&amp;')
6th Jan 2018, 7:22 AM
visph
visph - avatar
0
your answer is very clear. I guess I'm forgetting the special characters in javascript. And for textarea, it is. something new to me (just learning). thank you very much, have given answer. : D
6th Jan 2018, 8:14 AM
Muhammad Amin
Muhammad Amin - avatar