Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > document.selection.createRange()

Reply
Thread Tools

document.selection.createRange()

 
 
Martin Nadoll
Guest
Posts: n/a
 
      04-20-2009
Hello,

i have a form
<form name="ftext" id="ftext">
<textarea id="text" name="text"></textarea>
</form>
now i fill in a few words, lets say 'HelloWorld'. Now i put my focus in this
form between Hello and World because i want JavaScript to fill something in
there by a function called "fillInFormOne()".

and than i have another form:
<form name="another" id="another" onSubmit="fillInFormOne(nr)">
<textarea id="txt" name="txt"></textarea>
</form>
Whats going on in real is more complicated, so please dont ask, why i do it
like this. I made things simple here.

My Problem:
when i go into the textarea of form 2 my form 1 loses focus, so i have to
tell the function in the parameter"nr", where focus was before, so that this
function can edit document.forms['ftext'].elements['text'].value at the
right place between "Hello" and "World".

But how to find this value?
I need something like
document.forms['ftext'].elements['text'].selectionStart.value
Also it should work in Gecko and IE

Thanks for any help on that,
Martin Nadoll


 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      04-20-2009
Martin Nadoll wrote:
> i have a form
> <form name="ftext" id="ftext">


The required `action' attribute is missing.

> <textarea id="text" name="text"></textarea>
> </form>
> [...]
> My Problem:
> when i go into the textarea of form 2 my form 1 loses focus, so i have to
> tell the function in the parameter"nr", where focus was before, so that this
> function can edit document.forms['ftext'].elements['text'].value at the
> right place between "Hello" and "World".
>
> But how to find this value?
> I need something like
> document.forms['ftext'].elements['text'].selectionStart.value


Remove `.value', and store the reference to the previously focused element
somewhere, e.g.

<script type="text/javascript">
var ref = null;
</script>

<... onfocus="ref = this">

<... onfocus="foo(ref)">

You should avoid naming elements "text", though.

> Also it should work in Gecko and IE


The above (save the `.value') works in Gecko, createRange() (in your Subject
header![1]) works in IE/MSHTML.


HTH

PointedEars
___________
[1] <http://jibbering.com/faq/#posting>

P.S.: The pronoun, I, is always spelled with a capital letter.
P.P.S.: There is de.comp.lang.javascript
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57