I have 2 input boxes. 1=original, 2=result. I want to replace the space in the #box2 with "-" (dash).
So I have:
$("#box1").on('input', function() {
var stts = $(this).val();
dashed = stts.replace(/ /g, "-");
$("#box2").val(dashed);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="box1" placeholder="original" />
<input type="text" id="box2" placeholder="dashed string" />
But the problem is when the original box1 having "-" inside. When a space is pressed. There're double dashed "--" in the destination.
The question is : how to override the original "-" (dash). So it have only one "-" inside the destination? - https://jsfiddle.net/kcsyjrmL/
Working here : https://jsfiddle.net/kcsyjrmL/4/ (thnx to gurvinder372)
Working2 : https://jsfiddle.net/kcsyjrmL/5/ (thanx to Jp Mohan, fixing space-space)