Reputation: 88
What is best code, for auto add text in the end textfield. I have a code already but it removes the $ sign when i add anything in it. This is previous code:
$(document).ready(function(){
$("#price").on("keyUp",function(index,there){
$(there).val(
$(there).val().replace("$","") + "$"
);
});
});
in HTML
<input id="input_B" class="rate" value="$" type="text" disabled>
Upvotes: 0
Views: 164
Reputation: 943
Do check below code
$(document).ready(function(){
$( "#price" ).keyup(function() {
$("#input_B").val("$ "+ $("#price").val());
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="input_B" class="rate" value="$" type="text" disabled>
<input id="price" type="text" placeholder="Type Here" />
Upvotes: 1