Adam Ramadhan
Adam Ramadhan

Reputation: 22820

jquery text change when input change

How can we do like the bottom, the simple way ?

enter image description here ?

it updates when we change the input.

Upvotes: 5

Views: 16943

Answers (2)

Jacob Relkin
Jacob Relkin

Reputation: 163318

Say you had the following HTML:

<input type="text" id="textbox"/>

<span>http://twitter.com/<span id="changeable_text"></span></span>

Your JS would listen for the keyup event.

$('input#textbox').keyup(function() {
   //perform ajax call...
   $('#changeable_text').text($(this).val());
});

Upvotes: 8

Marko
Marko

Reputation: 72230

Just attach to the keyup event of that textbox and update a span accordingly.

The textbox and span

<input type="text" id="txt-url-suffix" />
<div>Your public profile: http://www.twitter.com/<span id="url-suffix" /></div>

And some simple jQuery

var $urlSuffix = $("#url-suffix");
$("#txt-url-suffix").keyup(function() {
    var value = $(this).val();
    $urlSuffix.text(value);
});

Upvotes: 6

Related Questions