How to simulate Enter keydown using JavaScript?

Discussion in 'JavaScript' started by ayeyam, Jun 3, 2021.

  1. #1
    hey guys I'm trying to send a message through this website: https://www.emeraldchat.com I should input a message into the text field then click enter. I tried to do this:

    document.querySelector("#room-input").value = "hi";
    evt = new Event("keydown", { code: "Enter", key: "Enter", keyCode: 13 });
    document.querySelector("#room-input").dispatchEvent(evt);
    <textarea id="#room-input" placeholder="Say Something..."></textarea>

    But it doesn't work, even if I input the message manually then try to press enter using the script it doesn't work, any ideas please?
     
    ayeyam, Jun 3, 2021 IP