
March 6th, 2013, 11:22 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 24
Time spent in forums: 3 h 29 m 22 sec
Reputation Power: 0
|
|
Code:
<script type="text/javascript">
function formatText(el,tag){
var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.sel ectionEnd);
if(selectedText!=''){
var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
el.value=el.value.replace(selectedText,newText)
}
}
</script>
</head>
<body>
<form action="" id="myForm">
<textarea name="myTextarea" rows="12" cols="50">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</textarea><br>
<textarea name="mytextarea2" rows="10" cols="50">His is my second textarea and I want the below buttons work for it as well.</textarea><br>
<input type="button" value="Bold" onclick="formatText(myTextarea,'b')">
<input type="button" value="Italic" onclick="formatText(myTextarea,'i')">
<input type="button" value="Underline" onclick="formatText(myTextarea,'u')">
The above code is to put the selected text inbetween the tags.Like this i want to do for font size. Is it possible to do.If so please tell me how to do.
|