1

I have a basic chatbot I created and need the user to be able to interact with the app via button pushes. On each 'turn' (when a user responds) I append controls that look like these:

Controls appended

$("#controls").append(
                  '<button class="options one" value="certifications" id="certifications" type="button">My Certifications</button>' +
                  '<button class="options one" value="videos" id="video" type="button">My Videos</button>' +
                  '<button class="options one" value="login" id="login" type="button">My Account</button>'  
            );

From here, I have a function that takes the value/id of the clicked button and that picks what the bot reponds with, like so:

Push user's value into chat window, respond with correlated value

// Pushes user's selected values as text chats
$("#controls").on("click touchstart", ".options", function() {
    // Remove buttons on click
    $("#controls button.options").remove();
    var b_val = $(this).val();

    var newMsg = text;

    var prevState = $("#conversation").html();
    if (prevState.length > 3) {
        prevState = prevState;
    }

What could be causing this click not to work? I am using a delegated on click since it's a dynamic element, but that doesn't seem to fix anything.

Thanks for taking a look!

knocked loose
  • 3,142
  • 2
  • 25
  • 46

0 Answers0