Forum Discussion

DamienLouis's avatar
DamienLouis
Community Member
15 days ago

Access to Items data

Hi,

In my project I have rectangular shapes with text on them. Is there I way to get this text with javascript and put it into a SL variable when the user clicks one of these rectangle.

best regards,

Eric

 

  • You could do with Javascript, but simple way is to add a trigger to adjust the value

  • Nedim's avatar
    Nedim
    Community Member

    There are several ways to accomplish this using JavaScript, depending on the initial setup. In the example below, I have three text-type variables: b1Text, b2Text, and b3Text. Each button contains text (e.g., "Button") inside it, and the code updates the corresponding variables based on the data-acc-text attribute of each button when clicked.

    var buttons = document.querySelectorAll('[data-acc-text*="Button"]');
    
    buttons.forEach((button, index) => {
        button.addEventListener('click', function() {
            var text = button.getAttribute('data-acc-text');
            setVar('b' + (index + 1) + 'Text', text); 
        });
    });

    However, I agree with Phil. I believe JavaScript isn't necessary in this case and may be an overly complex or unnecessary approach, as this could be solely handled by Storyline using triggers to set the values of the variables when each button is clicked.