user237784
user237784

Reputation: 33

how to get textbox value into label using jquery

How can I get the value of textbox into label when I click on a button using jquery.

I know how to write the click event in jquery. But when I write something like

$('#labelID').val() = $('#textboxID').val();

I get an error saying 'cannot assign to a function result'

Please help

Upvotes: 2

Views: 11899

Answers (3)

mitsu
mitsu

Reputation: 430

  var value = $("#textbox1").val();
                $("#label1").html(value);
                return false;

Upvotes: 0

Josh Mein
Josh Mein

Reputation: 28625

$('#labelID').html($('#textboxID').val());

Upvotes: 1

Jan Hančič
Jan Hančič

Reputation: 53931

$('#labelID').html ( $('#textboxID').val() );

val/html methods in jQuery act as getters and as setters. If you pass a value to them then they will set the value/html of the element to the passed value. If you just call val() you will get the value of the element.

Upvotes: 8

Related Questions