Forum Discussion

JenniferJack's avatar
JenniferJack
Community Member
2 months ago

Numeric Entry equal to a specific value

Hey, all. I am working on a numeric entry activity and I am wondering if it is possible to set a numeric entry equal to a value of 150 when the user clicks on that numeric entry field. I created an image of the number 150 highlighted in blue, and put the numeric entry on top of that. It currently functions so that when the user clicks on the numeric entry, the image with the highlighted blue 150 becomes hidden, so it looks like it disappeared from the text box. However, I want it to look like only the highlight disappears and the number 150 remains. So I created a trigger to set the numeric entry to "150" when the user clicks in the numeric entry field. However, it is not working. Does anyone know how to make this work? Thanks!

  • I was able to do this, but had to resort to JavaScript. Using this method, the input box will be set to 150 if the input box current value is empty. I have included a very basic storyline file demonstrating the functionality.

    initEvents = function()
    {
      const numberinput = document.querySelectorAll('input[type=text].acc-clickable');
      numberinput.forEach(function (input) {
        input.addEventListener('click', function (e) {
          console.log("click");
          if (e.target.value === "") {
            e.target.value = "150";
            e.target.dataset.dv_value = "150";
            const inputid = e.target.id.replace("acc-", "");
            const inputvisible = document.querySelector('.slide-object-textinput.shown[data-model-id="'+inputid+'"] input[type=text]');
            inputvisible.value = "150";
            inputvisible.dataset.dv_value = "150";
          }
        });
      });
    }
    setTimeout(initEvents,100);

     

  • Hi Jennifer,

    I have attached the .story file for your review. While Sam's JavaScript solution worked for me, I used a button that changes its state when the user clicks on the numeric entry field. Depending on the button state, the numeric field is set to a value of 150. I was just thinking of an easy and simple solution that would not include JavaScript.

  • I was able to do this, but had to resort to JavaScript. Using this method, the input box will be set to 150 if the input box current value is empty. I have included a very basic storyline file demonstrating the functionality.

    initEvents = function()
    {
      const numberinput = document.querySelectorAll('input[type=text].acc-clickable');
      numberinput.forEach(function (input) {
        input.addEventListener('click', function (e) {
          console.log("click");
          if (e.target.value === "") {
            e.target.value = "150";
            e.target.dataset.dv_value = "150";
            const inputid = e.target.id.replace("acc-", "");
            const inputvisible = document.querySelector('.slide-object-textinput.shown[data-model-id="'+inputid+'"] input[type=text]');
            inputvisible.value = "150";
            inputvisible.dataset.dv_value = "150";
          }
        });
      });
    }
    setTimeout(initEvents,100);

     

    • JenniferJack's avatar
      JenniferJack
      Community Member

      Hello! Thank you so much for putting the effort into helping me with this. I downloaded the storyline file and it worked. However, when I tried to replicate the actions in my course, it did not work the same way. The number "0" appeared in the textbox as soon as the timeline started on the layer.

  • Nedim's avatar
    Nedim
    Community Member

    Hi Jennifer,

    I have attached the .story file for your review. While Sam's JavaScript solution worked for me, I used a button that changes its state when the user clicks on the numeric entry field. Depending on the button state, the numeric field is set to a value of 150. I was just thinking of an easy and simple solution that would not include JavaScript.

    • JenniferJack's avatar
      JenniferJack
      Community Member

      Hey, all! I played with both solutions and they both worked! Thank you both so much for your suggestions. And now I know multiple ways to make it work!

      The only thing I did differently was I used a text entry instead of a numeric entry because I wanted to be able to set the text entry back to a value of "blank" when the layer was revisited. I do not think numeric entries allow you to set a value of "blank."