Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strange behaviour - serialize

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, when i made:

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

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

What i want is send the fraction value, that is showed in the input box, but as i said, not sent to the insert.php

Any idea ? thanks

like image 229
daniel__ Avatar asked Oct 22 '11 14:10

daniel__


1 Answers

At the beginning during the init of the slider an <input type="hidden" name="input0" ... /> will be created.
After using the slider this input get the current slider value (a number between 0 and sizes.length - 1). The onChange sets an other html input tag with the value from the array called sizes.
While submitting the serializeArray() takes the values of all input fields which have a name attribute.
In my EXAMPLE I gave the input field that will be filled at the onChange a name attribute, so the 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>
like image 136
scessor Avatar answered Oct 20 '22 02:10

scessor