Forums

Launch Javascript from a Dropdown EVENT

Asterix 26 Aug, 2016
Hi Support, I have a dropdown box and want to launch a javascript function from that dropdown events. The event allows only 1 liners. My script has multiple lines as per below: This works if adding the JavaScript for page load on the setup TAB / load javascript and will populate my dropdown, but I want to launch it from a selection in a dropdown EVENT option. Can you help?

Script I wish to run from the dropdown EVENT:

window.onload = function () {

jQuery.get('http://myserver/data/mytextfile.txt?t='+new Date().getTime(), function(data) { var textArea = data;var arrayOfLines = textArea.split("\n");var index;var a = arrayOfLines;
for (index = 0; index < a.length; ++index) {
var x = document.getElementById("MyDropdown");
var option = document.createElement("option");
option.text = a[index];
x.add(option);
}
});
};
GreyHead 26 Aug, 2016
Hi Asterix,

I have just replied to your email asking the same question, Please don't ask twice.

At the bottom of the Action list in the Events tab of your dropdown is a 'function' entry - that will let you call a JavaScript function when a particular value is selected. I think that will do what you need. (Though the function should not be wrapped in the window.onload() {} in this case.)

Of course you can also call your function directly from jQuery if you prefer.

Bob
This topic is locked and no more replies can be posted.