append string to textbox contents?

14,952

Solution 1

use jquery .val to set the text box value , it should do it

http://api.jquery.com/val/

Solution 2

pretty easy task with jQuerys .val()help method:

$('button').click(function(event) {
    $('input:text').val(function(index, val) {
        return val + event.target.value;
    });
});

Demo: http://www.jsfiddle.net/QFm7K/

Solution 3

or

$('button').click(function() {
    $('textarea')[0].value += $(this).val();
});
Share:
14,952
nkcmr
Author by

nkcmr

Updated on June 04, 2022

Comments

  • nkcmr
    nkcmr almost 2 years

    pretty simple, I have buttons but i want to add their value to a textbox when they are clicked, how would i go about doing this in jQuery? They are all numbers and their cant be more than 10 in the textbox.

  • Pointy
    Pointy about 13 years
    the superscript link is cute :-)
  • jAndy
    jAndy about 13 years
    I INVENTED IT! ME ME ITS MEEE maybe patrick dw won't see this :p
  • Developer
    Developer almost 11 years
    Hi how can I use this when I am having multiple textboxes, i need to append the text for focused control