I have a form that allows me to add to a list using js. I want to be able to send all the data in this list to my bottle server, but I can’t get any data there. How to get all elements in my report for publication on server.py? How to access this data after publication?
Relevant Code:
server.py:
@bottle.route('/saveList', method='POST')
def save_list():
forms = bottle.request.get('the_list')
print forms
return bottle.redirect('/updatelist')
list.tpl
<select multiple="multiple" id="the_list" name="the_list">
%for item in my_ list:
<option>{{item}}</option>
%end
</select>
EDIT:
I am trying to get the whole list, not just the selected values. The user adds to the multimedia through a text field, button and JS; so I want to get all the values (or all new values).
EDIT 2:
I used the answers provided along with some js to get the desired result:
$('.add_to_the_list').click(function (e) {
...
var new_item = $('<option>', {
value: new_item_str,
text: new_item_str,
class: "new_item"
});
...
function selectAllNewItem(selectBoxId) {
selectBox = document.getElementById(selectBoxId);
for (var i = 0; i < selectBox.options.length; i++) {
if (selectBox.options[i].className === "new_item") {
selectBox.options[i].selected = true;
}
}
}
...
$('#submit_list').click(function (e) {
selectAllNewBG("the_list")
});