Tuesday 15 September 2015

javascript - jquery array not getting all the values as well as not sent to laravel controller -


I have created two custom jquery functions that make an array of data when the checkbox is checked. I tried to designate the array as the value of an input field (type = hidden) and sent it to the inferior controller. The problem is that when I check multiple fields, the array is not properly populated, take only one value and it is sent to the controller. I have to take all the checked values ​​as an array and it will be sent to the lavender controller. Please help me in this regard. I pasted my stuff below:

jquery:

  & lt; Script & gt; Var Olvs = []; Delete Function Category () {$ ('Select Category: Check'). Each (function () {allvals = $ (this) .val ();}) Returning Olvisions; } Function subcategoryDelete () {$ ('. Subcategory Select: Check'). Each (function () {allvals = $ (this) .val ();}) Returning Olvisions; $ ('# DeleteArray') $ ('# DeleteArray') ARTR ('A' $ ('Value', 0);}) $ ('. Subcategory Select) Click (function () {deleteArray = subcategoryDelete (); $ ('# deleteArray)' $ '(' deleteArray ')') .attr ('value', deleteArray); $ ('# DeleteValue') Attr ('value', 1);})}) & lt; / Script & gt;  

html form:

  {{form :: open (array ('url' = & gt; manage-class / delete '))} } & Lt; Input type = "hidden" id = 'deleteArray' name = 'deleteArray []' & gt; & Lt; Input type = "hidden" id = 'deleteValue' name = 'deleteValue []' & gt; & Lt; Button id = 'deleteBtn' class = "btn btn-sm red pull-right" & gt; & Lt; I class = "fa fa-times" & gt; & Lt; / I & gt; & Lt; / Button & gt; {{Form :: off ()}}  

route:

  root :: post ('/ management-category / delete', 'category control @ DeleteCategory ');  

Controller:

  Public function deleteCategory () {$ deleteArray = input :: get ('deleteArray'); $ DeleteValue = Input :: find ('deleteValue'); Var_dump ($ deleteArray); Die (); }  

debug result:

  array (1) {[0] => String (1) "2"}   

Where you say allvals = $ (This) .val (); Each time the value of the alloy is overwritten so it will only store the value of the checkbox checked for the last time.

The solution is to add new values.

  allvals.push ($ (this) .val ());  

No comments:

Post a Comment