I have a form, the first .class has 5 input:text boxes in it. I want to be able to clear all the text boxes with the click of a button. I've tried it a few ways and it's not working... here's what I've done.... (FYI, I have more classes in the form so I can't use .reset.
<table class="orderLine1 formFont" width="900">
<tr>
<td width="395">Product Name:<br><input class="ProductName" type="text" size="65"></td>
<td width="97" class="formFontDisabled">Prod ID:<br><input class="Product_ID ffd" type="text" size="5" disabled></td>
<td width="78" class="formFontDisabled">UPC:<br><input class="UPC ffd" type="text" size="13" disabled ></td>
<td width="67" class="formFontDisabled">List Price:<br><input class="ListPrice ffd" type="text" size="7" disabled></td>
<td width="67">WholeSale:<br><input class="WholeSalePrice ffd" type="text" size="7" disabled></td>
<td width="56">Quantity:<br><input class="qty addLine" type="text" size="7"></td>
<td width="60" class="formFontDisabled">Line Total:<br><input class="subTotal ffd" type="text" size="10" disabled></td>
<td width="44"><button class="OFDeleteButton">Delete</button><button class="OFClearLine" >OFClearLine</button></td>
</tr>
</table>
$(document).ready(function(e) {
$(function clearFirst() {
$('.orderLine1').find(':input').each(function() {
switch(this.type) {
case 'text':
$(this).val('');
break;
}
});
});
$('.OFClearLine').click(function(e) {
clearFirst();
});
});
$(function(){
$('.OFClearLine').bind('click', function(){
$('.orderLine1').reset();
});
});
More info: OFClearLine is the class for the button I want to use & orderLine1 is the class of the form.
Thanks in advance!
To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.
$('input'). val('') will do the job.
Just use: $("input:empty"). length == 0; If it's zero, none are empty.
$(function() {
$('.OFClearLine').click(function() {
$('.orderLine1 input[type="text"]').val('');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With