python - Jquery and Django multiple checkbox -
I'm making a start in jquery, please bear with me I have a jquery function that allows me to select multiple checkboxes and create a string as follows:
function getSelectedVals () {var tmp = []; $ ("Input [name = 'check']). (Function () {if ($ (this) .attr ('checked')) {check = ($ (this) .val ()); tmp push Check);}}); Var filter = tmp.join (','); Alert (filter) return filter;}
I then call a djgenja view function and string I pass the following way:
selected = getSelectedVals (); var myurl = "/ bill / delete /? I have a display view function on the server; Id = "+ selected; $ .exax ({Type:" GET ", URL: Myrale, Data: selected, cache: incorrect});
Which is iterative on checkbox value and creates a list.
delete def (request): in the listidx for global Mayer idx listidx = idx.split (','): Value = myarray [int (l)] myarray.remove (value) return HttpResponse ("/ billed / jqtut /")
The problem is that all the indexes on the server form the GET string In
What I see, you do it in the vicinity, you should set the same name on all the checkboxes. I do not know why you send it by GET, I want to send it by POST. / P>
& lt; input type = "checkbox" name = "vehicle" value = "bike" /> input type = "checkbox" name = "vehicle" value = "a And "/ & gt; & Lt; Input type = "checkbox" name = "vehicle" value = "airplane" /> Then, use the getlist () method in your view: delete def (request): value = request.POST.getlist (u ' Vehicle ') # Handling goes here.
But anyway, unless you really need custom stuff (although special rules are not enough to break the rules;), use the Django form already Checkbox list is OOTB I'm not sure why you use javascript in this case.
Comments
Post a Comment