sam.wiltshire
Posts: 0
Joined: Thu Mar 01, 2012 11:33 pm

Adding multiple items (from checkboxes) to a database array

Hey there

I am trying to add multiple items from a check box to a database array. The intention is that the user can pick and choose their preferences and all of these will be saved in the same array (ideally this will be very scalable as I intend to add at least a hundred checkboxes).

I have noticed two different posts which sort of seem like they may be in the right direction: https://getsatisfaction.com/tiggzi/to... and https://getsatisfaction.com/tiggzi/to... however they only seem to be working for when items are added to the array one at a time and not at the same time.

Any help that you can provide will be much appreciated!

Also, FYI I am fairly new to javascript and tiggzi so please err on the side of more detail vs less if possible. Thank you in advance!

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Adding multiple items (from checkboxes) to a database array

Hello! Could you clarify please where do you want to save items? In localStorage or to DB?

sam.wiltshire
Posts: 0
Joined: Thu Mar 01, 2012 11:33 pm

Adding multiple items (from checkboxes) to a database array

Hey Marina,

Preferably to DB for now, but it would probably be useful to save to local storage as well for a few functionality ideas that I have coming up.

Sam

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Adding multiple items (from checkboxes) to a database array

Hi Sam,

You would need JavaScript code to do this:

  • read all the values that need to be saved in database;

  • generate JavaScript array;

  • save an array in database using Rest Service.

    What data should be saved in array: selected items in Checkbox Group or other?

sam.wiltshire
Posts: 0
Joined: Thu Mar 01, 2012 11:33 pm

Adding multiple items (from checkboxes) to a database array

Hi Katya

Thanks for this.

Ok cool. I would assume that we would use a local storage variable to store the array.

And yes, I want to save the value of the checkbox if it is checked. I.e. if we have:

[ ] blue
[x] red
[x] black
[ ] yellow
[x] green

Would be then stored as an array: colours["red", "black", "green"]

Also, if you have any suggestions on where to start, resource-wise for JS for this then that would be much appreciated.

Sam

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Adding multiple items (from checkboxes) to a database array

Hello! You can search for jQuery Mobile documentation. For example to find component by name you can use:

codeTiggzi('checkboxgroup')/code

to find check box items:

codeTiggzi('checkboxgroup').find('input[type=checkbox]')/code

to select check box items which are checked:

codeTiggzi('checkboxgroup').find('input[type=checkbox]').filter(function(i, elem) {return $(elem).prop("checked");} )/code

sam.wiltshire
Posts: 0
Joined: Thu Mar 01, 2012 11:33 pm

Adding multiple items (from checkboxes) to a database array

Thanks Marina, I'll give it a shot over the weekend/Monday (It is St Paddy's day this weekend after all!)

sam.wiltshire
Posts: 0
Joined: Thu Mar 01, 2012 11:33 pm

Adding multiple items (from checkboxes) to a database array

Hi Marina

I have been trying to do this and, along with a few Stack Overflow articles I have managed to get the selected check box values into a comma separated alert.

However, I have been trying to follow one of your other threads to try and get it into a local storage variable with no luck. The thread is here - https://getsatisfaction.com/tiggzi/to...

My code looks like the following:

In a separate JS file:
precode
function save(item, arrName) {
var arr = JSON.parse(localStorage.getItem(arrName));
if(arr == null) {
arr = new Array();
}
arr.push(item);
localStorage.setItem(arrName, JSON.stringify(arr))
}

function myload(arrName) {
var arr = JSON.parse(localStorage.getItem(arrName));
if(arr == null) {
arr = new Array();
}
return arr;
}
/code/pre

And what I am calling when the user clicks on the submit button after selecting their checkboxes:
precode
var userTeams = [];
$(document).ready(function () {
var selectedValues="&quot
$checkedCheckboxes = $("input:checkbox[name=basketballNBA_checkboxes]:checked");
$checkedCheckboxes.each(function () {
//save( $(this).val() , 'userTeams');
selectedValues += $(this).val() +",&quot
});
alert(selectedValues);
});
/code/pre

In Chrome dev tools it appears that I am getting the following error on the first line in the seperate JS files - Uncaught Syntaxerror: unexpected token u.

Any help would be greatly appreciated!

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Adding multiple items (from checkboxes) to a database array

Hello,
I'll take a look.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Adding multiple items (from checkboxes) to a database array

I cannot reproduce this.
Could you please share your app with a href="mailto:support@tiggzi.com" rel="nofollow"support@tiggzi.com/a and provide exact steps to reproduce?

Return to “Issues”