From d2fc72cd520a1a505ae710279603506b16fd9a09 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 18 Mar 2017 16:08:32 +0100 Subject: Fire change event on project select box Remove our timeouts for the moment to focus on getting the Module select box populated. Fire a change event on the Project select box using the technique and code described here: http://stackoverflow.com/questions/2856513/how-can-i-trigger-an-onchange-event-manually/2856602#2856602 --- timetasker.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/timetasker.js b/timetasker.js index 8fae786..fdb4346 100644 --- a/timetasker.js +++ b/timetasker.js @@ -19,17 +19,17 @@ popupate_select(client_0, CLIENT); - popupate_select(project_0, PROJECT); - // need to add a damn event trigger in order to get options to load + + fire_select_event( + popupate_select(project_0, PROJECT) + ); + window.setTimeout(function() { popupate_select(module_0, MODULE); - }, 1500); - window.setTimeout(function() { - popupate_select(task_0, TASK); - }, 500); - window.setTimeout(function() { - popupate_select(work_type_0, WORK_TYPE); }, 500); + + popupate_select(task_0, TASK); + popupate_select(work_type_0, WORK_TYPE); // popupate_select(date_0, ''); time_0.value = TIME; popupate_select(billable_0, BILLABLE ? 't' : 'f'); @@ -41,8 +41,14 @@ for (var i = 0; i < options.length; i++) { if (options[i].textContent === name) { element.value = options[i].value; - return; + return element; } } } + + function fire_select_event(element) { + var event = document.createEvent('HTMLEvents'); + event.initEvent('change', false, true); + element.dispatchEvent(event); + } })(); -- cgit v1.2.3