Forum Moderators: open

Message Too Old, No Replies

selecting text on a webpage, then insert it into a form field

         

dmmh

5:22 pm on Dec 14, 2005 (gmt 0)

10+ Year Member



whats wrong with this function?
Im quite the Javascript noob, cant figure it out :D

<!-- Begin
function copyit(theField) {
var selectedText = document.selection;
if (selectedText.type == '<b style="color:black;background-color:#99ff99">Text</b>') {
var newRange = selectedText.createRange();
theField.focus();
theField.value = newRange.<b style="color:black;background-color:#99ff99">text</b>;
} else {
alert('select a <b style="color:black;background-color:#99ff99">text</b> in the page and then press this button');
}
}
// End -->

gives me an error:

missing name after . operator
line 7, char 83

theField.value = newRange.<b style="color:black;background-color:#99ff99">text</b>;

DrDoc

7:41 pm on Dec 18, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



theField.value = newRange.<b style="color:black;background-color:#99ff99">text</b>;

That's what it is complaining about. I usually don't work with ranges and selections because of the poor support for it, so I can't really tell you what you're supposed to do to get it working, but I do know that the whole newRange.<b style="color:black;background-color:#99ff99">text</b> thing is what's causing the error.