Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to real time display input value with jQuery?

<input type="text" id="name" />
<span id="display"></span>

So that when user enter something inside "#name",will show it in "#display"

like image 361
omg Avatar asked Sep 10 '09 07:09

omg


People also ask

How to get value from input field in jQuery?

To get the textbox value, you can use the jQuery val() function. For example, $('input:textbox'). val() – Get textbox value.

How to get display value in jQuery?

jQuery val() Method The val() method returns or sets the value attribute of the selected elements. When used to return value: This method returns the value of the value attribute of the FIRST matched element.

How to get input field text jQuery?

Answer: Use the jQuery val() Method You can simply use the jQuery val() method to get the value in an input text box. Try out the following example by entering something in the text input box and then click the "Show Value" button, it will display the result in an alert dialog box.


1 Answers

You could simply set input value to the inner text or html of the #display element, on the keyup event:

$('#name').keyup(function () {
  $('#display').text($(this).val());
});
like image 90
Christian C. Salvadó Avatar answered Sep 21 '22 16:09

Christian C. Salvadó