Strange Behavior - Serialization

I have this code:

var sizes = ["1/9","1/8","1/7","1/6","1/5","1/4","1/3","1/2","1/1","2/1","3/1","4/1","5/1","6/1","7/1","8/1","9/1"]; var slider = new dijit.form.HorizontalSlider({ value:8, name:"value"+[i], slideDuration:0, onChange:function(val){ dojo.byId('value'+[i]).value = sizes[val]; }, minimum:0, maximum:sizes.length-1, discreteValues:sizes.length, intermediateChanges:"true", },node); 

now that i have done:

  $("#custom").submit(function() { var formdata = $("#custom").serializeArray(); $.ajax({ url: "insert.php", type: "post", dataType: "json", data: formdata, success: function(data) { } }); 

For example, if I select the value 1/8, it is sent as 1 or 9/1 as 16.

I want to send the fraction value, which is displayed in the input field, but, as I said, is not sent to the insert.php file

Any idea? thanks

+6
source share
1 answer

At the beginning, during the initialization of the slider, <input type="hidden" name="input0" ... /> will be created.
After using the slider, this input will receive the current value of the slider (a number between 0 and sizes.length - 1 ). onChange sets another html input tag with a value from an array called sizes .
When sending serializeArray() values โ€‹โ€‹of all input fields that have the attribute name are taken.
In my EXAMPLE, I gave an input field that will be populated in the onChange a name attribute, so serialization takes both values.

HTML:

 <form action="#" id="custom"> <div id="slider0"></div> <input type="text" id="value0" data-dojo-type="dijit.form.TextBox" name="value0" /> <input type="submit" value="submit" /> </form> 
+3
source

Source: https://habr.com/ru/post/899869/


All Articles