Issues with manipulating a drop down in Javascript

I’m currently using vanilla JS to match a given string, and then populate a drop down based on the match. I want to be able to click the drop down once to populate the drop down, but I currently have to click twice to then select the option, which would then add the same entries again (which isn’t so much of an issue as once an option was selected, I can always reset the length to 0 so the user would likely not notice). I was thinking perhaps I need two event listeners instead of one but unsure of what direction to go or perhaps a "clickdown" and "clickup" event (if they even exist for mouse clicks?).

I’m still very much a beginner and not sure if what I am wanting to achieve is possible in one click or perhaps my approach is incorrect, so any pointers would be great.

document.getElementById('form').addEventListener('click', function() {
    function addType(mactype) {
        var type = document.getElementById('mode');
        var option = document.createElement('option');
        option.text = mactype;
    var macinput = MACinput.value;
    var macoutput = MACoutput.value;
    if (macinput.length > 0) {
        var pattern = new RegExp("....-....-....");
        if (pattern.test(macinput) == true) {
        addType("Huawei -> Colon");
        addType("Huawei -> HP");
        addType("Huawei -> String");

Stack Overflow Asked by orgg on November 15, 2021

0 Answers

Add your own answers!

Related Questions

Rotating and moving object (follow into mouse) – Javascript

0  Asked on January 8, 2021 by karlos-margaritos


Method scrollToItemAtIndexPath is not working on iOS 14

3  Asked on January 7, 2021 by david-vittori


Adding horizontal gradient to borderline

1  Asked on January 7, 2021 by tarvo-mesepp


How to use flags with python’s regular expressions in string notation?

1  Asked on January 7, 2021 by werner-germn-busch


How to migrate repos from SVN to Gerrit?

0  Asked on January 7, 2021 by fresher


Text File Problems

1  Asked on January 7, 2021 by taco_attack


Is there an easy way to get out of this IF loop?

3  Asked on January 7, 2021 by matias


How to proxy image with Netlify Lambda

0  Asked on January 6, 2021 by xaver-fleer


a method that converts a daynumber into a date

4  Asked on January 6, 2021 by leenieke19


Ask a Question

Get help from others!

© 2021 All rights reserved.