Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery how to clear all the input:textfields of a .class on a form. Not working for me

Tags:

jquery

forms

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.

The Form...

<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>

The Script Test # 1

   $(document).ready(function(e) {
    $(function clearFirst() {
         $('.orderLine1').find(':input').each(function() {
             switch(this.type) {
                 case 'text':
                    $(this).val('');
                    break;
                 }
             });
        });

    $('.OFClearLine').click(function(e) {
        clearFirst();
    });
    });

The Script Test # 2

  $(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!

like image 334
Monty Avatar asked Nov 08 '11 17:11

Monty


People also ask

How do I clear all inputs in a form?

To clear all the input in an HTML form, use the <input> tag with the type attribute as reset.

How do I empty an input value with jQuery?

$('input'). val('') will do the job.

How do you check all input field is not empty in jQuery?

Just use: $("input:empty"). length == 0; If it's zero, none are empty.


1 Answers

$(function() {
  $('.OFClearLine').click(function() {
    $('.orderLine1 input[type="text"]').val('');
  });
});
like image 170
PeeHaa Avatar answered Oct 13 '22 01:10

PeeHaa