Forum Discussion

AndrewDunn's avatar
AndrewDunn
Community Member
9 years ago

Disabling a text entry field

I have a page with text entry fields. I want to disable / enable fields depending on the value of a variable. Is it possible to enable/disable text entry fields?

  • Bumping this thread to add another reason for disabling text entry fields:
    When reviewing a quiz question, a user can still tab through the focus order and change their answer, even with an object blocking the fields. Then when they return to the results slide it will mark that question as correct.

  • Nedim's avatar
    Nedim
    Community Member

    You can disable a text entry field at any time with just a few lines of JavaScript. Share your scenario or setup, and we'll make it work if feasible.

    • Griffingriffind's avatar
      Griffingriffind
      Community Member

      I can't share the specific file since it contains proprietary information but would you be able to share the lines of Javascript that are needed?

    • Nedim's avatar
      Nedim
      Community Member

      No problem, Rick. Glad it worked. 

  • Nedim's avatar
    Nedim
    Community Member

    To target a unique ID of an input element, you might use something like id="acc-5nkaJ2cbCf9". To find and reference this ID in your script, you would first need to get it from the developer console and then update your script with a line such as document.getElementById('acc-5nkaJ2cbCf9'). If you need to use the same script on a different slide or with a different TEF, you would need to repeat this process to update the code. Now, imagine you have multiple TEFs that you want to enable or disable based on certain actions. This approach would not be reusable without constantly updating the code. Getting all inputs at the same time and then isolating the specific one you need by its index number proves to be the easiest method that works.

  • Nedim's avatar
    Nedim
    Community Member

    We can also make this more efficient by creating global functions to avoid repeating code, and run this code only when the timeline starts on this slide.



    Now we can call a function to disable the TEF under certain conditions:
    window.disableInput(0); // 0,1,2,3...



    Or call a function to enable the TEF under different conditions or when something else happens: window.enableInput(0); // 0,1,2,3...