As per my knowledge TextBox displays only plain-text. So u can try with a div/span. OR think of any other alternative. Here is an example
<html>
<head>
<title>Untitled Document</title>
<script type="text/javascript">
function FormatSelectedWord(txtBox,style)
{
var selectedText = document.selection
? document.selection.createRange().text
: txtBox.value.substring(txtBox.selectionStart,txtBox.selectionEnd);
if(selectedText!='')
{
var newText='<'+style+'>'+selectedText+'</'+style+'>';
txtBox.value=txtBox.value.replace(selectedText,newText)
spOutput.innerHTML=txtBox.value;
}
}
</script>
</head>
<body>
<input type="text" name="txtBox"> </input>
<input type="button" value="Bold" onclick="FormatSelectedWord(txtBox,'b')">
<input type="button" value="Italic" onclick="FormatSelectedWord(txtBox,'i')">
<span id="spOutput"></span>
</body>
</html>
Hope this will help
Best Regards,
Niladri Biswas
Mahendrabasutkar, if this helps please login to Mark As Answer. | Alert Moderator