...

View Full Version : Manipulate Selected Text?



ubh
10-14-2008, 05:02 AM
never mind

Philip M
10-14-2008, 09:15 AM
Is this what you require?


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function formatText(el,tag){
var selectedText = document.selection?document.selection.createRange().text:el.value.substring(el.selectionStart,el.sel ectionEnd);// IE:Moz
var newText='<'+tag+'>'+selectedText+'</'+tag+'>';
if(document.selection){ //IE
document.selection.createRange().text=newText;
}
else{ //Moz
el.value=el.value.substring(0,el.selectionStart)+newText+el.value.substring(el.selectionEnd,el.value .length);
}
}
</script>
</head>

<body>
<form name="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>
<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');" />
</form>
</body>
</html>


This works with all browsers. Author Kor.


You can't teach an old leopard new spots. - Sports commentator

ubh
10-14-2008, 04:11 PM
never mind

ubh
10-14-2008, 05:21 PM
never mind

Philip M
10-14-2008, 06:28 PM
Posting Guideline 5) Do not bump your thread repeatedly when you don't get a response. Sometimes when you post for help, you may not get a response in a timely matter, if at all. Forums aren't wishing wells, and some questions will fall through the cracks. That's a fact of life. It's ok to occasionally bump a thread, but only when done after an ample amount of time (ie: 2-3 days) have passed without a response, and never more than once, . Your thread is no more important than another member's when it comes to the amount of attention it should receive.

Bumping after only 1 hour 10 minutes tends to put people off who might otherwise have helped you.

Any document.write statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page. And document.write only works with pages that the browser processes as HTML. Pages the browser processes as XML cannot use document.write at all.
Pages defined with an XHTML DOCTYPE should be served as XML rather than HTML, but in turn this creates problems with IE6 and below.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum