changzhi
changzhi

Reputation: 2709

Get text when inputing content with Input tag by Javascript

I will show you Fiddle link about my program question.

<label for="test">Username:</label>
<input type="text" id="test">
<p id=""></p>
$("#test").onclick(function(){
    alert('xx');                
})

I want to realize this function: p tag real-time displays input tag's content when I input something. I'll be very happy if you answer me.

Thank you.

Upvotes: 0

Views: 60

Answers (2)

Joseph
Joseph

Reputation: 1086

You can attach it to the keyup event that way it updates with every keystroke.

Try this http://jsfiddle.net/Z2Xwr/1/

$("#test").keyup(function(){
        $('#paragraph').html($(this).val());               
 })

Upvotes: 1

Rikesh
Rikesh

Reputation: 26431

You can use keyup event,

$("#test").keyup(function(){
         $("#para").html(this.value) ;               
 });

FIDDLE DEMO.

Upvotes: 1

Related Questions