Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   document.selection.createRange() (http://www.velocityreviews.com/forums/t938478-document-selection-createrange.html)

Martin Nadoll 04-20-2009 01:59 PM

document.selection.createRange()
 
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



Thomas 'PointedEars' Lahn 04-20-2009 06:22 PM

Re: document.selection.createRange()
 
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 ;-)


All times are GMT. The time now is 07:09 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


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