I have built a form in HTML and it is working as I like it, except the reset button.
I would like one reset button that clears all the user input and the verdict. This clears the input but leaves the verdit.
I have been looking all over online but can't find how to do this. Here is my code:
<form name="myform">
<table border="5px solid" border-color= "black #444 #888 #ccc" width="50%" cellpadding="1" cellspacing="1" class="table-striped" style="margin-right: calc(25%); margin-left: 10px width: 80%;">
<tbody>
<tr>
</tr>
<tr>
<td style="width: 92.7258%;">
<br> Enter the estimate $
<input maxlength="10" size="5" name="b" value="">
<br> The amount from the letter $
<input maxlength="10" size="5" name="c" value="">
<br> The number of months, enter 12 for a full year.
<input maxlength="2" size="5" name="d" value="">
<br> Enter the quote amount. $
<input maxlength="10" size="5" name="e" value="">
<p></p>
<input onclick="perc1()" type="button" value="Calculate">
<input type="reset" value="Reset">
<br> <div id="verdict">
<br>
</td>
</tr>
</tbody>
</table>
</form>
The verdict is like a paragraph long and I couldn't figure out how to send something that long to another input. That's why the div id and the subsequent problem.
Thanks for your guidance! =D
Your <div>
dedicated to verdict is not part of the form fields so it is not cleared by the reset button.
You can add an onreset
function to the form tag and define a JavaScript function to reset the form and verdict.
<form name="myform" onreset="resetForm()">
and function
function resetForm() {
// Clear input values
document.myform.b.value = '';
document.myform.c.value = '';
document.myform.d.value = '';
document.myform.e.value = '';
// Clear verdict
document.getElementById('verdict').innerHTML = '';
}