I have a textarea on a form. I have javascript buttons above it to add html tags (i.e. <b>, </b>) to it. I have two problems.
I'd like to be able to add the tag wherever the cursor is in the text area instead of appending it to the end. If this is not simple, it's really not important.
More importantly, I'm trying to get the focus back to the textarea after adding the tag. If it has to be putting the cursor at the end of the text, so be it. as of right now I can't even get the focus back to anywhere in the textarea. Here is the code I'm using:
I have multiple textareas in the one form (submissionForm), and they are named paragraph1, paragraph2, and so on. There is a bold button for each, and they are named boldButton1, boldButton2, and so on. My onclick is Bold(1), Bold(2), and so on.
Thanks in advance for any help.
I'd like to be able to add the tag wherever the cursor is in the text area instead of appending it to the end. If this is not simple, it's really not important.
More importantly, I'm trying to get the focus back to the textarea after adding the tag. If it has to be putting the cursor at the end of the text, so be it. as of right now I can't even get the focus back to anywhere in the textarea. Here is the code I'm using:
Code:
function Bold(textBoxNumber)
{
selectedText = false;
if (browserVersion >= 4)
{
selectedText = document.selection.createRange().text;
}
if (selectedText)
{
// Add tags around selection
document.selection.createRange().text = "<b>" + selectedText + "</b>";
eval('document.submissionForm.paragraph'+textBoxNumber+'.focus()'); THIS LINE IS NOT WORKING 10/02/03
selectedText = '';
return;
}
else
{
if (eval('document.submissionForm.boldButton'+textBoxNumber+'.value == " B "'))
{
eval('document.submissionForm.boldButton'+textBoxNumber+'.value = " B* "');
eval('document.submissionForm.paragraph'+textBoxNumber+'.value += "<b>"');
}
else
{
eval('document.submissionForm.boldButton'+textBoxNumber+'.value = " B "');
eval('document.submissionForm.paragraph'+textBoxNumber+'.value += "</b>"');
}
return;
}
}
Thanks in advance for any help.