Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

My page is querying the "Database for Life Science Standards" that relate to "Structure and Function". The request successfully brings the values back to a LABEL that is EMBEDDED in a CheckBoxGroup.

What happens... the user gets the list of possibilities. The user can check the little check boxes. However, I cannot find a way to read what the user has checked.

I have looked online and I found this code from
https://getsatisfaction.com/apperyio/...:

var arr = new Array();
arr = Appery("guardianCheckBox").find(":checked").map(function(el) {
return el.val();
});
if (arr.length == 0) {
alert("Please select a guardian!");
return;
}
if (arr.length 2) {
alert("Please select only 2 guardians!");
} else {
var items = ['selectedGuardian', 'selectedGuardian2'];
$.each(arr, function(i, value){
localStorage.setItem(items, value);
});
addChild.execute();
}
// restore from localStorage
var items = ['selectedGuardian', 'selectedGuardian2'];
$.each(arr, function(i, key){
var value = localStorage.getItem(key);
Appery("guardianCheckBoxList")
.find("input[value='" + value + "']:first")
.prop('checked', 'checked')
.refresh();
});

var arr = new Array();
Appery("checkboxgroup").find(":checked").each(function(){
arr.push($(this).val());
});

=============================
I modified it for my purposes like this:
=============================

var arr = new Array([]);
arr = Appery("checkbox2_Standard").find(":checked").map(function(el) {
return el.val();
});
if (arr.length === 0) {
alert("Please select a standard!");
return;
}
if (arr.length 2) {
alert("Please select only 2 standards maximum.");
} else {
var items = ['NGSS_standard1', 'NGSS_standard2'];
$.each(arr, function(i, value){
localStorage.setItem(items, value);
});
addChild.execute();
}
// restore from localStorage
var items = ['NGSS_standard1', 'NGSS_standard2'];
$.each(arr, function(i, key){
var value = localStorage.getItem(key);
Appery("checkbox2_StandardList")
.find("input[value='" + value + "']:first")
.prop('checked', 'checked')
.refresh();
});

Appery("checkboxgroup").find("input:checked").each(function(){
alert($(this).text());
});

I understand conceptually that an array would need to be created when more than one standard is checked. With each new "Check" , an item would be added to the array. This code limits the number of standards to 2, which is close to what I want to do. I want to take all the "checked" boxes and store the results in a growing database. This way, at the end of the app, the user can print these "Standards" later in a final document. I am using the check boxes so the user doesn't need to type all the text for each standard.

FIREFOX browser is giving me these errors:

Errors on login:

----------------------------------------

Use of Mutation Events is deprecated.
Use MutationObserver instead. target-script-min.js:1271
ReferenceError: jsPDF is not defined pdfJavafromWeb.js:2
ReferenceError: Downloadify is not defined download_java_scriptprint.js:3
ReferenceError: Downloadify is not defined showpdf.js:3

and after that...

Errors when trying to use the checkboxes and javascript I modified:

----------------------------------------

TypeError: doc.fromHTML is not a function JavaScript3.js:14
Empty string passed to getElementById(). jquery.mobile-1.4.0.js:14607
Use of getPreventDefault() is deprecated. Use defaultPrevented instead. jquery-1.9.1.js:3346
Use of getAttributeNode() is deprecated. Use getAttribute() instead. jquery-1.9.1.js:2514
TypeError: el.val is not a function

Here are pictures of my database, the element names , and the GUI in use.

Image

Image

Image

Thank you for showing such care and mercy. I am doing my best to read and understand the previous posts. I know this question was asked but I am missing some key concepts of how the check boxes should work. I remember BASIC from the 1980s and I am trying to apply this knowledge to javascript. not bad, but a different animal for programming.

Can I better organize my files in the database? should I?

I know everyone's app logic is different, but I am trying to make this easy for the user, and what is easy for the user, is more difficult for the programmer.

Thank you thank you 1000x!

Alex

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

Hi Alex,

I see you still have this problem,

Don't worry, it's easy to implement what you want. We will help you with this issue at all.

At first you need make correct mapping for your checkboxes list. You need fill "value" field for each checkbox item.

See details on screen shot: http://prntscr.com/43sb95/direct

Then you can use following code get checked items into JS variable:

pre

//Note you need replace "mobilecheckboxgroup_38" with your checkboxlist component name.
var ckeckedItems = jQuery('[dsid="mobilecheckboxgroup_38"] input[type="checkbox"]:checked');

console.log("Checked items count = " + ckeckedItems.length);

//Iterate through checked items.
for(var i = 0; i < ckeckedItems&#46;length; i++){
var checkedItem = jQuery(ckeckedItems);

Code: Select all

 var checkedValue = checkedItem&#46;val(); 

 &#47;&#47;Just out this value to browser console&#46; Please check out it to see results&#46; 
 console&#46;log("checkedItem[" + i + "] = " + checkedValue); 

 &#47;&#47;Here you can use "checkedValue" JS variable as you need&#46; 

};

/pre

Note: you need run this code after user set checkboxes state. For example on "submit/save/create" button click.

Also - this code has some debug information for you. Please open your browser console and see this information.

Regards.

Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

//Note you need replace "checkbox2_Standard" with your checkboxlist component name.
var checkedItems = jQuery('[dsid="checkbox2_Standard"] input[type="checkbox"]:checked');
console.log("Checked items count = " + checkedItems.length);
//Iterate through checked items.
for(var i = 0; i < checkedItems.length; i++){
var checkedItem = jQuery(checkedItems);
var checkedValue = checkedItem.val();
//Just out this value to browser console. Please check out it to see results.
console.log("checkedItem[" + i + "] = " + checkedValue);
//Here you can use "checkedValue" JS variable as you need.
}

there were some spelling mistakes for "Checked" , but I fixed those words and pasted the final code here . You must have been up late ! Thanks for your help, this code returned the values in the browser, but I cannot get rid of the other errors.

Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

I don't understand why things like "downloadify" are not installed.

Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

SyntaxError: syntax error jspdf.js:6

SyntaxError: syntax error downloadify.min.js:6

Empty string passed to getElementById(). jquery.mobile-1.4.0.js:14607

Use of getPreventDefault() is deprecated. Use defaultPrevented instead. jquery-1.9.1.js:3346

Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

ok i found out why this happened, but now i have new errors , and i cannot log on like i used to...

very sad, I want to show my friends my progress using the QR code and testing links.

Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

Empty string passed to getElementById(). jquery.mobile-1.4.0.js:14607

Code: Select all

      $(document).off("click", '#loginScreen_mobilecontainer2 [name="loginButton"]').on({ 
             click: function() { 
                 if (!$(this).attr('disabled')) { 
                     try { 
                         loginService.execute({}) 
                     } catch (ex) { 
                         console.log(ex.name + '  ' + ex.message); 
                         hideSpinner(); 
                     }; 

the login uses this command or code, and the browser doesn't like this part:

Code: Select all

            console.log(ex.name + '  ' + ex.message);
Alex Van Name
Posts: 0
Joined: Mon Jun 30, 2014 7:36 pm

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

ok, I found the bug.

The way my app is set up, it is using an iPAD template.

This divides the screen into 2 parts.

When I Image

So when I set an event, like PAGE SHOW and I ask the browser to SETCONTENT to a web page, the app doesn't login.

How do I use the SETCONTENT so I don't mess up my app?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Checking the values of Checkboxes made after a Database request returned a list, with the Checkboxes embedded in a drop-

Hi Alex, I'm not sure I'm understanding you right. What is event "SETCONTENT", what does it?

Return to “Issues”