javascript and TextBox problem

K

kusanagihk

To all,

I've got a problem using Javascript to control the properties of a html
textbox.
I was wondering if I could change the cursor index / position of the
text within a textbox object.

ie. for example the text of a textbox is "hello tom"; and I want to
shift the cursor's index to 6 which points at the letter "t" of the
word "tom"

by the way, I am also finding ways to selectively highlight the text of
a textbox, like I would like to highlight / select just the word "tom".

so is it possible??? or any alternatives???
 
C

Csaba Gabor

To all,

I've got a problem using Javascript to control the properties of a html
textbox.
I was wondering if I could change the cursor index / position of the
text within a textbox object.

ie. for example the text of a textbox is "hello tom"; and I want to
shift the cursor's index to 6 which points at the letter "t" of the
word "tom"

by the way, I am also finding ways to selectively highlight the text of
a textbox, like I would like to highlight / select just the word "tom".

so is it possible??? or any alternatives???

Range manipulation in Firefox is not well supported and buggy, to boot.
However, the way to move the caret and to select text is through
textarea.setSelectionRange(startPos, endPos). Find the current
position via textarea.selectionStart and textarea.selectionEnd. If the
two positions are different, then you have a selection, otherwise just
the caret. The corresponding IE operations are completely different.

Csaba Gabor from Vienna
 
K

kusanagihk

Thx Csaba Gabor,

I think the javascript I'm writing must be workable on both mozilla and
ie6; so can you tell me about the handling on ie6 too?

thx
 
K

kusanagihk

yup, not sure why Mozilla and IE can't stick to the same specifications
(eg. W3C's DOM spec).

I just found that parts of the javascript DOM model (eg. creating a
textbox using document.createElement ("input")) might need to set
different attributes to make that textbox object containing the same
appearance and behaviours on both browsers....

it is also kind of messy and troublesome in writing the javascript code
to be runnable on netscape 4.x and mozilla.... again, many different
methods or attributes have to be taken into concern....
 
R

Randy Webb

(e-mail address removed) said the following on 5/19/2006 3:30 AM:
yup, not sure why Mozilla and IE can't stick to the same specifications
(eg. W3C's DOM spec).

Because IE has it's own specs. If those specs happen to agree with W3C,
then great. If they don't, it doesn't make one ounce of difference to MS.
I just found that parts of the javascript DOM model (eg. creating a
textbox using document.createElement ("input")) might need to set
different attributes to make that textbox object containing the same
appearance and behaviours on both browsers....

Example?

And what is "both browsers"? Would they be Camino and Konqueror? Or
Opera and ICEBrowser? Don't fall into the "two browser" trap.
it is also kind of messy and troublesome in writing the javascript code
to be runnable on netscape 4.x and mozilla.... again, many different
methods or attributes have to be taken into concern....

Who writes for NN4 anymore?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top