Reputation: 1
I have a input field where a user enters in a name at the end of a quiz and i have tried various methods of clearing the field. The page cannot re-load as the user is able to restart a quiz.
Here is my HTML:
<div class="js-quiz-submit">
<input type="text" class="js-name" placeholder="Please Enter Your Name"/>
<input type="button" class="js-submit" value="Submit"/>
</div>
Upvotes: 0
Views: 2010
Reputation: 1
Html:
<div class="js-quiz-submit">
<input type="text" id="js-name" class="js-name" placeholder="Please Enter Your Name"/>
<input type="button" class="js-submit" value="Submit"/>
</div>
Javascript:
document.getElementById('js-name').value='';
Upvotes: 0
Reputation:
I guess the better way will be :
document.querySelector(".js-name").value = "";
Upvotes: 0
Reputation: 4920
If your input field is in a form say #quiz-form
, then you can clear the fields of form as follows:
var form = document.querySelector('#quiz-form');
form.reset();
Upvotes: 1