How Do I Use a variable for the MouseClick?

Hi, we have been using an external .js file for all text in our html5 output so that the localization team can easily translate the content without having to fuss with the raw Hype file. We have done this by using the element IDs (for example, a text box).

However, I am not sure if this works for the MouseClick action. We’d like to store the url externally in the .js file since localization will change it, depending on the language. I am not sure how to set this up since the element ID for the element we are clicking on is already being used to have the text localized.

Is there another way to do this?

There are a couple of ways that you can do it. You could give the buttons a class and then use that similar to how you use the id’s.

Or your external .js text file could be structured to have two objects for each button. You would use an object like array.

For example.


var spanish = {"greeting": "hola", "url" :"http://someurl.com"}
var english =  {"greeting": "hello", "url" :"http://someotherurl_.com"}


window.selected= spanish


you then just get the values by using the keys with the variable. i.e


sometextbox.innerHTML = window.selected.greeting


window.open(window.selected.url);

Thank you so much for the fast response. I will try this.

When you say give a button a class, what do you mean? (I am very new to the more layered uses of Hype). I searched for class in the help but didn’t see anything. Can you please share more?

Thanks!

in the identity inspector there is a field under the Unique Element ID labelled “Class Name” here you can give any element a space separated list of classes.

red blue spanish iatesomechickenlastnight

The difference is that ID can only be one where classes (Classlist) can contain many.

You would then check against this list and if you find what you’re looking for then you can act upon it.

var myElement = document.getElementByID('someElementWithAListOfClasses');
if (myELement.classList.contains('spanish')){
    // do something great! Like change the language.
}

This probably won’t translate :slight_smile: into what you’re doing and I wouldn’t use it but you get the idea. :smiley:

1 Like

Ahh okay. Thank you so much. This helps immensely.