Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Empty textbox using Jquery

Tags:

jquery

textbox

I'm able to hide the 'tr' when 'Remove' is clicked. with the following code.

$("a#minus").bind("click", function(e){
    $(this).closest('tr').hide();
});

But I also want to clear the content of the 2 text boxes (id of the textbox's are dynamic [frm_Expense_expensesVO___strAmount and frm_Expense_expensesVO___memo] here '*' goes from 1 to infinity). Please help. Thanks

<table>
<tr>
    <td>
        Amount
    </td>
    <td>
        Memo
    </td>
    <td>    
        &nbsp;
    </td>
</tr>
<tr>
    <td>
        <input type="text" name="expensesVO[0].strAmount" value="2.30" id="frm_Expense_expensesVO_0__strAmount"/>
    </td>
    <td>
        <input type="text" name="expensesVO[0].memo" value="Five" id="frm_Expense_expensesVO_0__memo"/>
    </td>
    <td>
        <a id="minus" href="#">Remove</a>
    </td>
</tr>
<tr>
    <td>
        <input type="text" name="expensesVO[1].strAmount" value="3.45" id="frm_Expense_expensesVO_1__strAmount"/>
    </td>
    <td>
        <input type="text" name="expensesVO[1].memo" value="Six" id="frm_Expense_expensesVO_1__memo"/>
    </td>
    <td>
        <a id="minus" href="#">Remove</a>
    </td>
</tr>
<tr>
    <td>
        <input type="text" name="expensesVO[2].strAmount" value="" id="frm_Expense_expensesVO_2__strAmount"/>
    </td>
    <td>
        <input type="text" name="expensesVO[2].memo" value="" id="frm_Expense_expensesVO_2__memo"/>
    </td>
    <td>
        <input type="submit" id="frm_Expense_ExpenseAdd_plus" name="action:ExpenseAdd_plus" value="+"/>
    </td>
</tr>
<tr>
    <td>    
        <label id="frm_Expense_transactionVO_amount">5.75</label>
    </td>
    <td align="right">
        <input type="submit" id="frm_Expense_Cancel" name="action:ExpenseAdd_cancel" value="Cancel"/>
    </td>
    <td align="left">
        <input type="submit" id="frm_Expense_Save" name="action:ExpenseAdd_save" value="Save"/>
    </td>
</tr>

like image 680
Anand Rockzz Avatar asked Jan 18 '10 04:01

Anand Rockzz


People also ask

How do you make a blank text box in Javascript?

Set the value NULL of input field using document. getElementById('myInput'). value = ”

How remove textbox value after submit in jQuery?

find('input:text'). val(''); $('input:checkbox'). removeAttr('checked'); }); One will clear all text inputs.


1 Answers

$("a#minus").bind("click", function(e){
    $(this).closest('tr').hide().find('input:text').val('');
});

Note: Also see darmen's answer on why the selector a#minus will not work as desired.

like image 181
Chetan S Avatar answered Oct 01 '22 09:10

Chetan S