1

I've got a text box (called SMS) which is capable of having its value changed by selecting a button (addButton). See the JavaScript

<script>
$(document).ready(function(){
    $(document).on('click','.addButton',function(e){
        e.preventDefault();
        var search_val = $(this).attr('data-value');
        $('.sms').val(search_val);
    });

});
</script>   

I want to be able to add multiple values to this text box without the text boxes value completely updating each time.

For example: A user can write: hello, your name is (user select 'Name' button and value is inserted'. Your address is (user selects address button).

With my current solution, any button clicked will remove all value form the text box and just insert the value of which ever button was pushed.

Pete
  • 57,112
  • 28
  • 117
  • 166
blackers
  • 61
  • 7
  • 1
    are you looking for something similar to this? https://stackoverflow.com/questions/841722/append-text-to-input-field – Chris Li Sep 12 '18 at 13:25

1 Answers1

1

Use the function to update it's value:

$('.sms').val(function( index, value ) {
  return value + search_val;
});
Pete
  • 57,112
  • 28
  • 117
  • 166