Adding a select menu item


#1

Hi,

In the attached example, I am trying a simple test case to populate a select menu item from an array, this works on a html page but not within hype, I’m not sure what I am doing wrong.

Any help is appreciated.

RegardsPopulateSelect.hype.zip (10.9 KB)


#2
var myArray = new Array("1", "2", "3", "4", "5");

// Get dropdown element from DOM
var dropdown = hypeDocument.getElementById('selectNumber');
	
// Loop through the array
for (var i = 0; i < myArray.length; ++i) {
// Append the element to the end of Array list
el = document.createElement('option');
el.innerText = myArray[i];
el.value = myArray[i];
dropdown.appendChild(el);
}

console.log(dropdown)

The following will populate your select element. By the way you must put this in a rectangle not a HTML widget for it to work as you want from a timeline action and Hype function.


#3

Many thanks DBear, that work’s great!