Home > Net >  My TypeScript Button isn't responding to user input
My TypeScript Button isn't responding to user input

Time:12-01

function test(event)
{
    document.getElementById('ausgabe').innerHTML =
    'test';
}

document.addEventListener("DOMContentLoaded", (event) => {
    document.getElementById("input1").addEventListener("submit", (event) => {
        test(event);
    })
})
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

Clicking the Button does basically nothing. The website doesn't change when I'm clicking it.

CodePudding user response:

'submit' is an event of <form>, not of <button>.

Change your code to this:

function test(event)
{
    document.getElementById('ausgabe').textContent = 'test';
}

document.addEventListener("DOMContentLoaded", (event) => {
    const button = document.getElementById("input1");
    const form   = button.form;
    form.addEventListener("submit", (event) => {
        test(event);
    })
})
  • Related