I have a dropdown menu with an information tooltip icon next to it. When the user changes the selection in the dropdown and hovers over the info icon, a description for the selected item should appear as shown in the image:
https://i.sstatic.net/K1S64.jpg
Currently, I have a backend map of values where the key is the dropdown value and the value is the corresponding description. I want this map to be accessible in the frontend (JavaScript). There are several options available:
1- Make an AJAX call on each value change (inefficient due to unnecessary calls to the backend)
2- Pass the map as a JSON object to a hidden HTML element and retrieve it from there (complicated by escaping characters in JSON)
3- Use data attributes, but my framework does not support HTML5
4- Fetch the JSON via AJAX after page load and store it in a JavaScript variable (wasteful use of server resources)
5- Create a global variable in my JSP using declaration tags (not thread-safe and involves scriplets)
I opted for the fifth solution since the map is static and concurrency is not a major issue. Additionally, the framework I'm working with heavily relies on scriplets.
Does anyone have any other recommendations based on the solutions mentioned, or possibly offer alternative solutions?