Preventing button action until text input occurs

Right now, any letters I type into the text input will cause the Play button to change to Pause.

Could I set it up so that the text inputted would need to start off with a few letter characters in order for it to change from Play to Pause.

Example:
In order for it to change from Play to Pause.

mop’ has to be the first 3 letters proceeded by any other letter characters.

(function iife() {
    "use strict";
    const player = document.getElementById("player");
    const button = document.getElementById("button");
    const value = document.getElementById("input");
    const sent = document.getElementById("sent");
    const input = document.getElementById("clear");
    let canPlay = false;

    function playPauseIcon(play) {
        if (!canPlay) {
            return;
        }
        if (play) {
            button.classList.add("is-playing");
        } else {
            button.classList.remove("is-playing");
        }
    }
    button.addEventListener("click", function() {
        if (!canPlay) {
            return;
        }
        if (player.paused) {
            player.play();
            playPauseIcon(true);
        } else {
            player.pause();
            playPauseIcon(false);
        }
    });
    button.addEventListener("mousedown", function(evt) {
        if (evt.detail > 1) {
            evt.preventDefault();
        }
    }, false);
    sent.addEventListener("click", function() {
        player.src = value.value;
        player.src != "";
        player.volume = 1.0;
        playPauseIcon(true);
    });
    input.addEventListener("click", function() {
        value.value = "";
        button.classList.remove("is-playing");
        player.pause();
        canPlay = false;
    }, false);
    player.onloadstart = function() {
        if (value.value !== "") {
            canPlay = true;
            playPauseIcon(true);
        }
    };
}());

There doesn’t seem to be anything case-sensitive about this issue. I’ve asked for the thread to be renamed to something more appropriate.

1 Like

Thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.