Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove value of input using jQuery

Tags:

jquery

I need to remove some values from a hidden and text input box using jQuery, but somehow this is not working

Example:

<input type="hidden" value="abc" name="ht1" id="ht1" />
<input type="text" name="t1" id="t1" />

I use the following jQuery code to remove the values with an onclick event

$('#rt1').click(function() {
    $('#t1').val();  
    $('#ht1').val();  
});

Can I empty the contents of the input box and clear the value of the hidden field using jQuery?

like image 682
Elitmiar Avatar asked Oct 06 '09 10:10

Elitmiar


2 Answers

You should do this:

$('#rt1').click(function() {
    $('#t1').val('');  
    $('#ht1').val('');  
});

That is, pass an empty string. Either that, or use removeAttr (query.removeAttr('value')).

like image 102
Tamas Czinege Avatar answered Oct 11 '22 13:10

Tamas Czinege


$('#rt1').click(function() {
    $('#t1').attr('value', '');  
    $('#ht1').attr('value', '');  
});
like image 37
Mark Bell Avatar answered Oct 11 '22 13:10

Mark Bell