0

here is my code

I have tried using javascript with onClick but then my submit button won't work. Then I tried changing it into the normal button and it still won't work. I tried putting it into the form and still won't work. So, I don't know how to reset the button for my form. This is my school work and I'm still a student so please help me. I would appreciate your help soo much.

NAK SUSHI
  • 1
  • 1
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 21 '21 at 07:20
  • Is "Reset" button inside your `
    ` element?
    – Rayon Oct 21 '21 at 07:21
  • Welcome to SO. We are here to help, but you might find reading the site [help section](https://stackoverflow.com/help) useful when it comes to [asking a good question](https://stackoverflow.com/help/how-to-ask), and this [question checklist](https://meta.stackoverflow.com/questions/260648/stack-overflow-question-checklist). Code that you've worked on to solve the problem should include a [mcve], and be included in your question. – Andy Oct 21 '21 at 07:22
  • Why the form cannot be used? – The KNVB Oct 21 '21 at 07:24
  • [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Pan Vi Oct 21 '21 at 07:27

3 Answers3

0

The Form types: reset and submit need a context. I mean you have to wrap all inputs inside a form. <form>....</from>. Then reset has the context to reset all fields inside his context / form.

Otherwise if you dont want use form you can do it by Javascript.

function reset() {
  document.getElementById('input_1').value = ''
  document.getElementById('input_2').value = ''
}
<input id="input_1" value="Hello"><br/>
<input id="input_2" value="World">

<br/>
<button onclick="reset()">RESET</buton>
Maik Lowrey
  • 15,957
  • 6
  • 40
  • 79
0

You should use javascript for reset your inputs

Notice: Keep in mind that the Enter key also works when using the form

<div>
    <div id="like-form">
        <input type="text" placeholder="Name" />
        <input type="email" placeholder="Email" />
        <input type="password" placeholder="Password" />
    </div>

    <button type="button" id="like-reset">
        Reset
    </button>
</div>

You can use Ajax to submit information, But to reset

document.getElementById("like-reset").addEventListener("click" () => {

    // forEach
    [].slice.call(document.getElementById("like-form").children).forEach(input => {
        input.value = "";
    });

    // For
    const inputs = document.getElementById("like-form").children;
    for (let i = 0; i < inputs.length; i++) {
        inputs[i].value = "";
    }
});
Ali Yaghoubi
  • 1,258
  • 8
  • 15
-1

U should set all inputs and reset button inside form. Like so:

<form>
  <input type="text">
  <input type="reset" value="Reset">
</form>

That way it should work.

Bohdan Srdi
  • 144
  • 1
  • 6