Append text to input field
$('#input-field-id').val($('#input-field-id').val() + 'more text');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><input id="input-field-id" />
There are two options. Ayman's approach is the most simple, but I would add one extra note to it. You should really cache jQuery selections, there is no reason to call $("#input-field-id")
twice:
var input = $( "#input-field-id" );input.val( input.val() + "more text" );
The other option, .val()
can also take a function as an argument. This has the advantange of easily working on multiple inputs:
$( "input" ).val( function( index, val ) { return val + "more text";});
If you are planning to use appending more then once, you might want to write a function:
//Append text to input elementfunction jQ_append(id_of_input, text){ var input_id = '#'+id_of_input; $(input_id).val($(input_id).val() + text);}
After you can just call it:
jQ_append('my_input_id', 'add this text');