Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use jquery keyup on multiple input fields?

Tags:

jquery

keyup

I'm trying to output the values of multiple input-fields into a single div. But I simply can't get it to work. It will only output one of the input-fields into the div at a time.

This is my jquery:

var $output = $('#output-content-here');
  $('input').keypress( function() {
  $($output).text(this.value);
});

I have made a jsiddle to show you what i mean: http://jsfiddle.net/A7UbK/1/

Thanks.

like image 335
Andreas Avatar asked Feb 13 '26 04:02

Andreas


1 Answers

Try the following code using .map()

var $output = $('#output-content-here');

$('input').keyup(function () {
    $output.html(function () {
        return $('input').map(function () {
            return this.value
        }).get();
    })
});

Demo

Note : $output already contains jQuery object.

like image 163
Shaunak D Avatar answered Feb 23 '26 02:02

Shaunak D



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!