java - Javascript: Form element values to a Collection -
i have html page dinamycally changing number of select elements.
<script> function getvalues() { var selects = document.getelementsbytagname('select'), arr = array.prototype.slice.call(selects), selectvalues = arr.map(function (select) { homecoming select.value; }); homecoming selectvalues; } </script> <script type='text/javascript'> function moreselect() { (i = 0; < number; i++) { // append node random text container.appendchild(document.createtextnode("name " + (i+1) + ": ")); // create <input> element, set type , name attributes var input = document.createelement("select"); input.name = "name" + (i+1); container.appendchild(input); // append line break container.appendchild(document.createelement("br")); } </script> <form action="action"method="post" onsubmit="return getvalues;"> more selects (max. 9):<br> <p> <input type="number" id="name" name="name" value="0" min="0" max="9"><br /> <button type="button" onclick="moreselect()">add</button> <br> <p> <br> <div id="container" /></div> <p> <br> <br> <input type="submit" value="go"> </form>
i want collect values list or array before post method , give parameter list java controller this:
@requestparam("allvalues") list<string> allvalues
edit: edited it, doesn't works.
get selects, transform them real array array.prototype.slice
. can utilize map
values. getelementsbytagname
returns htmlcollection
, not back upwards map()
, etc.
var selects = document.getelementsbytagname('select'), arr = array.prototype.slice.call(selects), selectvalues = arr.map(function (select) { homecoming select.value; });
now selectvalues
array of select values.
java javascript html forms
No comments:
Post a Comment