Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

JavaScript - Button Not Being Detected?

Regarding the JavaScript below, I'm not sure why when I click this button:
<button class="btn btn-mobile btn-grp-next btn-next-funding_amount mt-5" data-name="btn-grp-next" type="button"><span>CONTINUE</span> <i class="icon-arrow-thin-right"></i><i class="spinner"></i></button>

Open in new window

The following code doesn't detect the "CONTINUE" button being clicked for some reason?  I do get into the function below but it is NOT passing the button element,  I get the same result as clicking anywhere on the page and NOT the continue button. The listener is attached to document.body.
var saveInfosInSessionStorage = function(event) {

    var target = event.target;
    console.log("#### ==>  target.type: " + target.type + "  ===>   target.dataset", target.dataset);
    if (target.dataset && (target.type == "button")) {
        var fType;
        if (target.dataset.value) {
            fType = target.dataset.value;
            switch (fType) {
                case "Fund Now":
                    ...
                    break;
                case "Fund Later":
                    ...
                    break;
            }

        } else if (target.dataset.name) {
            fType = target.dataset.name;
            switch (fType) {
                case "btn-grp-next":
                    console.log("============== CONTINUE BUTTON CLICKED =================");
                    break;
            }
        }
    }
};

Open in new window

The console.log on line #4  shows the type as undefined and shows the data.set as "DOMStringMap" . So it acts as if I never clicked the "CONTINUE" button?User generated image
I have no idea why this is happening or how to fix?  Thanks!
Avatar of Jon Norman
Jon Norman
Flag of United Kingdom of Great Britain and Northern Ireland image

Are the "Fund Now" and "Fund Later" buttons working? If so what is giving them a type of "button".
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MJ

ASKER

Thank you!
You are welcome.