This site always comes up with answers to my questions when using Google but I've struggled to find an answer to this so thought I would register, say hello and ask :)
I have a timetable (using html tables) and each cell is marked as selectable for jquery-ui selectable.
i then have a form with button that will use POST to book the selected cells.
<form method="get" action="../test" id="add">
<button type="submit" class="btn btn-primary">Book selected period(s)</button>
</form>
In the selectable serialize example it shows it selecting the numbers fine. but when I go hit the button (using GET for testing) it seems to get the wrong numbers. For example if i select cell 1 and click book, it shows cell_id=1 in the GET, but if i select cell 1 and cell 2, it loops through counting them, so GET shows cell_id=1, cell_id=1, cell_id=2 (so counting 1, then 1+1 rather than just 1+1)
this means if i select 5 cells, I get 15 results (1+2+3+4+5) rather than 5. Is there a way around this. this is what i have so far in the javascript:
$( "#selectable" ).selectable({
filter: ".selectable",
stop: function() {
$( ".ui-selected", this ).each(function() {
var data = $(this).data();
$(data).each(function(key, value){
var period_id = document.createElement("input");
period_id.setAttribute("type", "hidden");
period_id.setAttribute("name", "booking[1][period]");
period_id.setAttribute("value", data.period);
document.getElementById("add").appendChild(period_id);
});
});
}
});
In the bit above i'm getting the period_id from the cell which is taken from some other php. it works as intended if selecting single cells just not multi. if any other code is needed to help answer this, please let me know
thanks
edit as an addition, this is what i'm hoping to achieve (for a clearer understanding of what i mean). user sees timetable grid. they can select one cell and choose book, which would pass via POST an array of the period and day they selected to go to a booking.php. they also have the option of selecting multiple cells, and clicking book, which would then pass each cell as an array for booking so php could loop through all cell arrays and book multiple cells using their room/day id's as returned by the jquery selectable.
$(data)? It seems you're only interested indata.period, so a loop shouldn't be necessary.