0

I want to click the submit form button using javascript DOM manipulation with the textarea value. I have another button if I click on the button the form will be submitted.

<form class="sendXMPPMessage">
            <button type="submit" class="btn send-button fa fa-paper-plane" title="Send the message"></button>

            <textarea type="text" class="chat-textarea suggestion-box__input
                    chat-textarea-send-button
                    " placeholder="Message" aria-autocomplete="list" spellcheck="false"><!----><!----></textarea>
            <span class="suggestion-box__additions visually-hidden" role="status" aria-live="assertive" aria-relevant="additions"></span>
     
</form>

<button class="submit-message">Submit</button>

1 Answer 1

1

You could do this. You can listen to click event on .submit-message button and then once that is clicked call click method on .send-button

document.querySelector('.submit-message').addEventListener('click', () => {
  document.querySelector('.send-button').click()
})
<form class="sendXMPPMessage">
  <button type="submit" class="btn send-button fa fa-paper-plane" title="Send the message"></button>

  <textarea type="text" class="chat-textarea suggestion-box__input
                    chat-textarea-send-button
                    " placeholder="Message" aria-autocomplete="list" spellcheck="false"><!----><!----></textarea>
  <span class="suggestion-box__additions visually-hidden" role="status" aria-live="assertive" aria-relevant="additions"></span>

</form>

<button class="submit-message">Submit</button>

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you to send a message automatically we can do like this document.querySelector(".chat-textarea").value = "abcd"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.