Question

I just want to change the VALUE attribute of textbox on key up. But when I am typing something the value remains same in the mark up. I want to change it in mark up too. Here is my jsfiddle .

MARK UP

<input type="text" value="Type Your Name" id="textBox1" />
<span id="userName"></span>

jQuery

$("#textBox1").keyup(function () {

 $("#userName").text($(this).val());

});

Any help would be highly appreciated.

Was it helpful?

Solution

add this line to your code:

    $("#textBox1").attr('value', $(this).val())

check your updated fiddle http://jsfiddle.net/h5tpk/6/

OTHER TIPS

just wrap your code in

$(function(){

});

http://jsfiddle.net/h5tpk/5/

You could also access the textbox via:

$("#textBox1").keyup(function () {
  $("#userName").text($('#textBox1').val());
});

http://jsfiddle.net/#&togetherjs=kTauiAAFgR

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top