I have an input field and I want to append its text while typing in it and persisting the previous value in it
Following is the code
<input type="text" id="txt1" name="type_name" value="Value1-" onchange="dosomething()">
What I want is when the user starts typing it the starting text of input field should remain there which is "Value1-" and append the text in it like "Value1-3433".
I hope you get my point a little help on this will be appreciated.
is this what you want ?
DEMO
jQuery
HTML
Working Fiddle
Append a label with
position:absolute
HTML
<label id="lbl" for="txt1"></label> <input type="text" id="txt1" name="type_name" value="" />
And fire an
onchange
event, to change add theValue1-
and users input...Add
Value1
onchange
event$('#txt2').change(function () { var str = $(this).val().replace('Value1-',''); $(this).val('Value1-'+str); });
Finally, I guess what you needed is here...
If I got it correct,with pure JavaScript,this is what you need to do:
start()
when the page loads with<body onload="start()">
. Print the text "Value1-" in the input TextField. Since this function is called only once,the Value1- will be printed only once.function append()
which you should call usingonchange()
and do:`document.getElementById('outputText').value=document.getElementById('txt1').value.
Hope this helps.
Use the following code to achieve this.
Jquery code:
HTML Code:
Working Jsfiddle link
http://jsfiddle.net/spdZW/1/