JavaScript stops working when title is published

shiggins-9138
Community Member Posts: 9
Hi
As part of a Quiz, I'm trying to limit the maximum number of checkbox selections in a Multiple Response question using JavaScript. I've implemented the function outlined by Sergey Snegirev in Pg1 of his four-part tutorial...
if ($('input:checked').length == 3) {
alert($('input:checked').length);
$('input:not(:checked)').attr('disabled', true);
} else {
alert($('input:checked').length);
$('input').attr('disabled', false);
}
...which runs fine in the Lectora Online single page preview (checkboxes disabled at a count of 3 and popups show the correct numbers), but fails once the project is published. The popups still work so the JS is running, but it's failing to work out how many boxes been selected (popups always show a value of 0).
NOTE: I've implemented this JS function on each button rather than at page level as I've overridden the default checkbox image, but it works just fine within Lectora. I've also followed Sergey's tutorial on a blank project to test from scratch and I'm still having the same problem. I've seen this happen on other JS functions I've tested in the past.
What am I missing?
Thanks in advance
As part of a Quiz, I'm trying to limit the maximum number of checkbox selections in a Multiple Response question using JavaScript. I've implemented the function outlined by Sergey Snegirev in Pg1 of his four-part tutorial...
if ($('input:checked').length == 3) {
alert($('input:checked').length);
$('input:not(:checked)').attr('disabled', true);
} else {
alert($('input:checked').length);
$('input').attr('disabled', false);
}
...which runs fine in the Lectora Online single page preview (checkboxes disabled at a count of 3 and popups show the correct numbers), but fails once the project is published. The popups still work so the JS is running, but it's failing to work out how many boxes been selected (popups always show a value of 0).
NOTE: I've implemented this JS function on each button rather than at page level as I've overridden the default checkbox image, but it works just fine within Lectora. I've also followed Sergey's tutorial on a blank project to test from scratch and I'm still having the same problem. I've seen this happen on other JS functions I've tested in the past.
What am I missing?
Thanks in advance
Comments
-
-
Hi Robert
Thanks for looking into this. I've attached a mock-up of the page as a PKG.
Thanks again -
Hi Sam,
The original script is not compatible with Seamless Play Publish. So if you had published with the option "Publish for Seamless Play" unchecked it would have worked fine. To make it work for both cases (Seamless Play and non-Seamless Play), you need to access the HTML elements using getDisplayDocument() function when using jQuery (eg: $('input:checked',getDisplayDocument())).
I attached an updated version of your sample title; please give it a try. I also made another change: instead of putting the same code in each of the check boxes, I made it into a function called processCheckbox() and added to a second HTML Extension of type Header Scripting and call that function from each check box action. That way if you need to make a change to the script you only need to change in one place.
Regards,
Robert. -
-
Could you post this same solution in a form that the desktop software can open? I just posted an issue to the forum where my jQuery was working properly in both Run and Edge Preview, but not on the LMS (see https://community.trivantis.com/forums/topic/animationsactions-work-in-run-edge-preview-not-in-lms/ ).
I'd like to see if your solution can work for me too.
Categories
- 4.8K All Categories
- 6 New Feature Releases
- The Training Arcade®
- Arcades™
- 123 ✫ Announcements
- 9 ✪ Contests
- 34.1K eLearning Brothers® Products
- 33.6K Lectora®
- 31.6K Lectora Discussions
- 1.9K Lectora Feature Requests
- 71 Lectora User Groups
- 16 Asset Library
- 10 AssetLibrary Discussions
- 6 AssetLibrary Feature Requests
- 301 CenarioVR®
- 176 CenarioVR Discussions
- 125 CenarioVR Feature Requests
- 37 Rockstar Learning Platform®
- 25 Rockstar Learning Platform Discussions
- 12 Rockstar Learning Platform Feature Requests
- 4 Off-the-Shelf Course Library
- 3 Off-the-Shelf Course Library Discussions
- 1 Off-the-Shelf Course Library Feature Requests
- 114 CourseMill®
- 107 CourseMill Discussions
- 44 ReviewLink®
- 32 ReviewLink Discussions
- 12 ReviewLink Suggestions
- 2 The Training Arcade®
- 1 The Training Arcade Discussions
- 1 The Training Arcade Feature Requests
- 10 Additional Learning Products
- 2 Adobe®
- 4 Articulate®
- 2 Camtasia®
- Docebo®
- 1 iSpring®
- 1 Microsoft® PowerPoint®
- 930 All Things eLearning
- 5 Course Development Showcase
- 1 eLearning Brothers® Downloads
- 1 Compliance Training
- 11 eLearning Development
- eLearning Game Design
- 7 Instructional Design
- 545 Learning Management System (LMS) Integration
- 2 Mobile Learning
- 21 Visual Design
- 331 Web Accessibility
- 1.2K ♪ The Green Room
- 8 ♡ Community Feedback
- 7 Community Tips