Web Hosting Talk







View Full Version : javascript function: delete highleted text


mg-
02-18-2005, 09:03 PM
hi

how would i go about deleting the currentely highlighted text in a form field?


and only that text!

Dan L
02-18-2005, 09:09 PM
Automatically?

Seems like it would be really inaccurate to use.

mg-
02-18-2005, 09:18 PM
i want a form field to delete all the highlighted text when a function is called... I don't care if it seems stupid, it's something I need to do for the overall purpose

Nullified
02-18-2005, 09:29 PM
I don't believe that is possible, I could be wrong though.

mitchlrm
02-18-2005, 10:47 PM
Edit>Cut hhmmm...too simple I guess

Mitch

Nullified
02-18-2005, 10:50 PM
lol, mitchlrm. I was trying to figure out myself why he needs this done.

mg-
02-19-2005, 02:15 AM
so... noone has a solution?

mitchlrm
02-19-2005, 03:19 AM
Theoritically it is possible to do this way: (1) Use the onmousedown command to record the location where the user starts the highlight and the onmouseup to record the position where the highlight ends. On the onmouseup, you can start a javascript routine to do the delete.

In practice, it is very difficult to map coordinates to individual characters on the screen and it is possible that there may be differences in browsers.

Mitch

mg-
02-19-2005, 05:15 PM
It's for IE explorer only, and it's another function that is handling the highlighting:
createTextRange();

I have an auto complete doing every word in an array, each time a new word is being typed - the script I made works fine with keypresses, but it also has to work with an on screen keyboard I made - I need to remove the highlighted text before I run the auto complete - otherwise it'll use that highlighted text in the word - thinking it's already complete.

I've tried using fireevent and ****, to try and mimick a keypress to erase the highlighted text.. nothing works.