tech_support
06-19-2006, 09:39 AM
Hello,
I was wondering if you can do a script where when you type in a textarea and click on a button it has the value plus something else and minus the current value.
For example I'm typing text and then i want a <b> code around it replacing the original.
I want this:
<b>text text text</b>
Not this:
text text text<b>text text text</b>
Here's what I'm doing right now
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<script>
function insert(tag,endtag) {
var text = ""
var currentValue = document.form1.html.value
text = (document.all) ? document.selection.createRange().text : document.getSelection();
document.form1.html.value += tag + text + endtag
return true;
}
</script>
</head>
<body>
<div class="mainbody">
<form id="form1" name="form1" method="post" action="">
<textarea name="html" cols="100" rows="15">Type here...</textarea>
<input name="bold" type="button" id="bold" value="Bold" onclick="insert('<b>','</b>')"/>
</form>
</div>
</body>
</html>
I was wondering if you can do a script where when you type in a textarea and click on a button it has the value plus something else and minus the current value.
For example I'm typing text and then i want a <b> code around it replacing the original.
I want this:
<b>text text text</b>
Not this:
text text text<b>text text text</b>
Here's what I'm doing right now
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<script>
function insert(tag,endtag) {
var text = ""
var currentValue = document.form1.html.value
text = (document.all) ? document.selection.createRange().text : document.getSelection();
document.form1.html.value += tag + text + endtag
return true;
}
</script>
</head>
<body>
<div class="mainbody">
<form id="form1" name="form1" method="post" action="">
<textarea name="html" cols="100" rows="15">Type here...</textarea>
<input name="bold" type="button" id="bold" value="Bold" onclick="insert('<b>','</b>')"/>
</form>
</div>
</body>
</html>