<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form id="form" action="dbSetter.php" method="get">
<input type="button" name="bold" value="b" />
<input type="text" name="name" />
<script>
(function(){
var form = document.querySelector('#form');
var input = form.querySelector('[name="name"]');
form.bold.onmousedown = function() {
return false;
};
form.bold.onclick = function() {
var selected = input.value.substring(input.selectionStart, input.selectionEnd);
var before = input.value.substring(0, input.selectionStart);
var after = input.value.substring(input.selectionEnd);
input.value = before + '<b>' + selected + '</b>' + after;
};
})();
</script>
</form>
</body>
</html>
В IE8 работать не будет (там замуты с выделенным текстом)