document.selection.createRange()

Discussion in 'Javascript' started by Martin Nadoll, Apr 20, 2009.

  1. 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
     
    Martin Nadoll, Apr 20, 2009
    #1
    1. Advertising

  2. 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 ;-)
     
    Thomas 'PointedEars' Lahn, Apr 20, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Crowe
    Replies:
    1
    Views:
    4,555
    Andrew Crowe
    Sep 13, 2004
  2. Martin Karlsson
    Replies:
    1
    Views:
    111
  3. lawrence
    Replies:
    7
    Views:
    166
    Thomas 'PointedEars' Lahn
    May 19, 2004
  4. lawrence
    Replies:
    14
    Views:
    256
  5. Replies:
    2
    Views:
    288
Loading...

Share This Page