2

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

Josh Mein
  • 28,107
  • 15
  • 76
  • 87
user237784
  • 33
  • 1
  • 1
  • 6

3 Answers3

8
$('#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.

Jan Hančič
  • 53,269
  • 16
  • 95
  • 99
1
$('#labelID').html($('#textboxID').val());
Josh Mein
  • 28,107
  • 15
  • 76
  • 87
0
  var value = $("#textbox1").val();
                $("#label1").html(value);
                return false;
mitsu
  • 429
  • 2
  • 10
  • 23