Here is the solution
Javascript
function wraptext() {
var SelectionStart = document.getElementById("text").selectionStart;
var SelectionEnd = document.getElementById("text").selectionEnd;
var OldVal = document.getElementById("text").value;
var NewVal = OldVal.substring(0, SelectionStart) + " bla " + OldVal.substring(SelectionStart, SelectionEnd) + " bla " + OldVal.substring(SelectionEnd, OldVal.length);
document.getElementById("text").value = NewVal;
}
Html
<input type="text" id="text" value="123456" />
<input type="button" value="Click Me" id="btn" onclick="wraptext();" />
Check demo here http://jsfiddle.net/iamrmin/P7gr8/