Limiting checkboxes in a quiz

andrew-robertson
andrew-robertson Community Member Posts: 354 ♦ Idol ♦
edited March 31, 2021 in Lectora Desktop
Hi there -

I am attempting to follow the steps outlined in the blog post to limit the number of selections that can be done by a learner.
$(‘input’).click(check_and_limit);
function check_and_limit() {
  if ($(‘input:checked’).length == 3) {
    $(‘input:not(:checked)’).attr(‘disabled’, true)
  } else {
    $(‘input’).attr(‘disabled’, false)
  }
}
I continually get the error below.


I attempted using other lines of code to double check that it isn't me, but i get the same error message.

I am using IE11 due to our dependency on the Harman Flash Plugin for continued support until all of our learning products are transitioned.
Andrew R.
Developing content since 2010 using a mixed bag of tools.

Best Answer

  • wheels
    wheels Community Member, Administrator, Moderator, Rockstar Manager Posts: 695 eLearning ROCKSTAR Admin Team
    Answer ✓
    I've attached an example.

    You will need to download the attached zip, then remove the .zip extension. The file is a PKG file but interestingly our forum doesn't support that format (we'll have to fix that!).

    The example can be imported and will work in Desktop or Online. For Lectora Online you have to update the JavaScript action named OnShowRunJS there are comments as to what to update.

    The example shows how to set "known" names for objects and then use the Lectora Object API to do things like disable / enable buttons and to show or hide text blocks.

    You will also see that triv$ is used, if you have a current version of desktop or if you use online then that is how you can access the built in jQuery object.

    Additionally you will see the use of getDisplayWindow() and getDisplayDocument() which are necessary to support our seamless play publish option.

    Hope this helps show some possibilities with scripting in Lectora.

Answers

  • chris_willis
    chris_willis Rockstar Manager Posts: 68 eLearning ROCKSTAR Stage Manager
    Hi, @andrew-robertson - You've stumbled on an article from our archives. Lectora has gotten a lot smarter since that was written!

    If you use one of the standard question types available in Lectora you can double click the ? icon in the Explorer, and set attempts like this:


    ----------------------------------------------
    Chris Willis, Product Director, Lectora
    ◖⚆ᴥ⚆◗ "Where there's a Willis, There's a Way!"
  • andrew-robertson
    andrew-robertson Community Member Posts: 354 ♦ Idol ♦
    Thanks @chris_willis for the rapid response; however, I am looking to put checks/balances in place so that we are truly testing the learner fairly. For example, if I were to ask the following question with multiple responses....

    What colour are the leaves in the tree? Select 3.
    a) Red
    b) Green
    c) Yellow
    d) Purple

    And then have JQuery do the following for me...
    1. Not allow the user to click a 4th option if they've already selected 3, and display a message saying they've already selected 3 if they go for a 4th option.
    2. Keep the SUBMIT button disabled until they've selected 3 options.
    Andrew R.
    Developing content since 2010 using a mixed bag of tools.
  • andrew-robertson
    andrew-robertson Community Member Posts: 354 ♦ Idol ♦
    @wheels & @chris_willis - you two are amazing. Appreciate the support. If could buy you a coffee (or beer), I would. Cheers and enjoy the impending weekend.
    Andrew R.
    Developing content since 2010 using a mixed bag of tools.
  • chris_willis
    chris_willis Rockstar Manager Posts: 68 eLearning ROCKSTAR Stage Manager
    @andrew-robertson - Lectora users like you help us better understand how to make Lectora the most powerful and versatile eLearning authoring tool available!

    That (and the aforementioned coffee) is what gets me up in the morning. As for the weekend ...
    Cheers! :D
    ----------------------------------------------
    Chris Willis, Product Director, Lectora
    ◖⚆ᴥ⚆◗ "Where there's a Willis, There's a Way!"