Currently, the following form fields are being cleared out by the jQuery shown:
HTML form:
<form action="" method="post" id="add">
<legend>Add Mobile</legend>
<ol>
<li>
<label for="add_name">name</label>
<input type="text" name="name" id="add_name"></input>
</li>
<li>
<label for="add_model">model</label>
<input type="text" name="model" id="add_model"></input>
</li>
<li>
<label for="add_color">color</label>
<input type="text" name="color" id="add_color"></input>
</li>
</ol>
<button type="button" onclick="addMobile()">Submit</button>
<button type="reset">Cancel</button>
</form>
jQuery:
// clear out form fields
$('#add input[name="name"]').val('');
$('#add input[name="model"]').val('');
$('#add input[name="color"]').val('');
Is there a way to write a selector such that all inputs of type "text" in the form with an ID of "add" will be cleared out?
9/22/2019 edit:
The form fields get cleared out by jQuery as part of the addMobile()
function in an AJAX call. So, if the add is successful part of the .done
logic is to clear out the form fields. The purpose of the Cancel button is to give the user a way to clear out the fields manually if desired.