java - Javascript: Form element values to a Collection -


I have an HTML page in which the number of selection elements varies.

  & lt; Script & gt; Function getValues ​​() {var select = document.getElementsByTagName (select '), arr = Array.prototype.slice.call (select), selectValues ​​= arr.map (function (select) {return select. Value;}); Select return value; } & Lt; / Script & gt; & Lt; Script type = 'text / javascript' & gt; Work more selection () (for (i = 0; i & lt; num; i ++) {// Attach a node with a random text container. AppendChild (document.createTextNode ("name" + (i + 1) + ":")); // Set a & lt; Input & gt; element, its type and name attribute var input = document.createElement ("select"); Input.name = "name" + ( I + 1); container.appendChild (input); // Attach a line break container. AppendChild (document.createElement ("br");} & lt; / script & gt; & gt; form action = "action More options (9 max): "method =" POST "onsubmit =" get getValues; "& gt; & lt; b & gt; & lt; p & gt; Input type =" number "id = "Name" name = "name" value = "0" min = "0" max = "9" & gt; & lt; button type = "button" onclick = "more selection () "& Gt; Add & lt; / button & gt; & lt; br & gt; & lt; p & gt; & lt; br & gt; & lt; div id =" container "/> gt; & lt; / Div> 


I want to store this value before the list of POST method or array and to give this parameter list to my Java controller like this:

 < Code> @ RequestParam ("allvalues") list & lt; String & gt; All values ​​ 

Edit: I've edited it, but it does not work.

get all the selections, in a real array of Array.prototype.slice Transform by. Now you can use the map to get all the values ​​ getElementsByTagName a HTMLCollection , which is the map () , etc.

  var select = document .getElementsByTagName (select '), arr = Array.prototype.slice.call (select), selectValues ​​= arr.map (Function (select) {select select.value;});  

Now the value is selected is an array of values ​​selected.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -