I'm a beginner with Javascript and especially cross-browser
Javascript. I got this working in IE, but not in Netscape 7. It seems
like, in Netscape, every time I click on a button, the focus shifts to
that button, so there is no text to be selected. What should I do?
Below you'll see some code that I have in one of my forms. I was
hoping to have these buttons and when I click on them they would take
selected text from a textarea box and replace it with the text but
surrounded with the HTML tags I wanted. But I can't get this to work.
Why?
<script language="javas cript"
function wrapSelectionBo ld (element) {
var range = document.select ion.createRange ();
if (range.parentEl ement() == element)
range.text = '<b ' + range.text + '<\/b ';
}
function wrapSelectionIt alic (element) {
var range = document.select ion.createRange ();
if (range.parentEl ement() == element)
range.text = '<i ' + range.text + '<\/i ';
}
function wrapSelectionBl ockQuote (element) {
var range = document.select ion.createRange ();
if (range.parentEl ement() == element)
range.text = '<blockquote ' + range.text + '<\/blockquote ';
}
function wrapSelectionBi gHeadline (element) {
var range = document.select ion.createRange ();
if (range.parentEl ement() == element)
range.text = '<h1 ' + range.text + '<\/h1 ';
}
function wrapSelectionSm allHeadline (element) {
var range = document.select ion.createRange ();
if (range.parentEl ement() == element)
range.text = '<h3 ' + range.text + '<\/h3 ';
}
</script
<input type="button" value="bold"
onclick="wrapSe lectionBold(thi s.form.inputId2 )" /
<input type="button" value="italic"
onclick="wrapSe lectionItalic(t his.form.inputI d2)"/
<input type="button" value="blockquo te"
onclick="wrapSe lectionBlockQuo te(this.form.in putId2)"/
<input type="button" value="big headline"
onclick="wrapSe lectionBigHeadl ine(this.form.i nputId2)"/
<input type="button" value="small headline"
onclick="wrapSe lectionSmallHea dline(this.form .inputId2)"/
<div class="formElem ent"
Change the brief description or introduction for your Weblog; <br
Or change the contents of your Webpage:<br
<textarea id="inputId2" name="formInput s[cbMainContent]"
class="textarea Input" </textarea
<p HTML into symbols? <input type="checkbox"
name="formInput s[usingHtml]" value="y" class="textarea Checkbox" </p
</div