focus after some text in a div tag

Discussion in 'Javascript' started by louvino@gmail.com, Mar 21, 2007.

  1. Guest

    Hi,

    I have :
    <div id="obj">Objet :</div>

    I want to put the focus AFTER the text "Objet :", is it possible ?

    Note : I don't want to create 2 div tags.
    , Mar 21, 2007
    #1
    1. Advertising

  2. Evertjan. Guest

    wrote on 21 mrt 2007 in comp.lang.javascript:

    > Hi,
    >
    > I have :
    > <div id="obj">Objet :</div>
    >
    > I want to put the focus AFTER the text "Objet :", is it possible ?
    >
    > Note : I don't want to create 2 div tags.


    "focus" can only be "on" a whole html element,
    [to make it "clickable" by key <enter>?]

    Certainly not "after" an element.

    I suppose you could be talking about a cursor.

    A cursor can only be applied in a writable element.

    Is your div writable?


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 21, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 21, 3:58 pm, "Evertjan." <> wrote:
    > wrote on 21 mrt 2007 in comp.lang.javascript:
    >
    > > Hi,

    >
    > > I have :
    > > <div id="obj">Objet :</div>

    >
    > > I want to put the focus AFTER the text "Objet :", is it possible ?

    >
    > > Note : I don't want to create 2 div tags.

    >
    > "focus" can only be "on" a whole html element,
    > [to make it "clickable" by key <enter>?]
    >
    > Certainly not "after" an element.
    >
    > I suppose you could be talking about a cursor.
    >
    > A cursor can only be applied in a writable element.
    >
    > Is your div writable?


    You're right. I 'm talking about the cursor.

    I have : <div id="obj" contentEditable="true" style="border : 1px
    solid; width:300px">Objet : </div>

    And I want the cursor to be after the semicolon.

    Thanks
    , Mar 21, 2007
    #3
  4. Evertjan. Guest

    wrote on 21 mrt 2007 in comp.lang.javascript:

    >> I suppose you could be talking about a cursor.
    >>
    >> A cursor can only be applied in a writable element.
    >>
    >> Is your div writable?

    >
    > You're right. I 'm talking about the cursor.
    >
    > I have : <div id="obj" contentEditable="true" style="border : 1px
    > solid; width:300px">Objet : </div>
    >
    > And I want the cursor to be after the semicolon.
    >


    Setting the cursor in a contenteditable div, IE only btw!,
    is not a trivial thing, as contenteditable seems a mess in itself.

    Perhaps setting a textrange could help, but I doubt it.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 21, 2007
    #4
  5. ASM Guest

    a écrit :
    >
    > I have : <div id="obj" contentEditable="true" style="border : 1px
    > solid; width:300px">Objet : </div>


    seems that doesn't work with my Firefox ...

    > And I want the cursor to be after the semicolon.


    and ...

    document.getElementById('obj').focus();
    document.getElementById('obj').click();

    ? ? des fois que ... May be ... with IE all is possible ?


    --
    Stephane Moriaux et son (moins) vieux Mac déjà dépassé
    Stephane Moriaux and his (less) old Mac already out of date
    ASM, Mar 21, 2007
    #5
  6. Guest

    The code :

    <div id="obj" contentEditable="true" style="border : 1px solid; width:
    300px">Objet :</div>
    <script>
    document.getElementById('obj').focus();
    document.getElementById('obj').click();
    </script>

    But not, the cursor is not after "Objet :".

    I search only a solution for IE >=6
    , Mar 22, 2007
    #6
  7. Evertjan. Guest

    wrote on 22 mrt 2007 in comp.lang.javascript:

    > The code :
    >
    > <div id="obj" contentEditable="true" style="border : 1px solid; width:
    > 300px">Objet :</div>
    > <script>
    > document.getElementById('obj').focus();
    > document.getElementById('obj').click();
    > </script>
    >
    > But not, the cursor is not after "Objet :".
    >
    > I search only a solution for IE >=6
    >
    >


    [please always quote on usenet]

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan., Mar 22, 2007
    #7
  8. Guest

    I find what I want.

    ><div id="obj" contentEditable="true" style="border : 1px solid; width:300px">Objet :</div>
    ><script>
    > document.getElementById("obj").focus();
    > var chaine;
    > var position;
    > chaine = document.getElementById("obj").innerHTML;
    > position = document.selection.createRange();
    > position.moveEnd("character", chaine.length);
    > position.collapse(false);
    > position.select();
    ></script>
    , Mar 22, 2007
    #8
    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. =?Utf-8?B?Tmlja3k=?=
    Replies:
    2
    Views:
    704
    Matt Berther
    Feb 20, 2005
  2. shruds
    Replies:
    1
    Views:
    778
    John C. Bollinger
    Jan 27, 2006
  3. M Wells
    Replies:
    0
    Views:
    135
    M Wells
    Oct 6, 2004
  4. visu
    Replies:
    4
    Views:
    289
  5. Roger
    Replies:
    3
    Views:
    319
Loading...

Share This Page