Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts

    interesting script here, anyone know how they did it?

    hey. a while back i was asking if it were possible to have the cursor in a textbox focus onload to a specific position in the text (that is defaulted in the textbox). in this case i wanted to know if i could have it default at the back of the text instead of the front.

    it seems they have found a way to do it here:
    https://www1.royalbank.com/cgi-bin/r...NGUAGE=ENGLISH

    any idea how they managed it?
    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Not too sure here but take a look at the following 2 examples.

    The first one puts the cursor at the beginning, the second at the end

    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Document Title</TITLE>
    </
    HEAD>
    <
    BODY onload="document.focusing1.focused.focus()">

    <
    form name="focusing1">
    <
    input type="text" name="focused" value="Focused" size=20>
    </
    form>

    </
    BODY>
    </
    HTML
    PHP Code:
    <HTML>
    <
    HEAD>
    <
    TITLE>Document Title</TITLE>
    </
    HEAD>
    <
    BODY onload="with(document.focusing2.focused){focus();value +=' '}">

    <
    form name="focusing2">
    <
    input type="text" name="focused" value="Focused" size=20>
    </
    form>

    </
    BODY>
    </
    HTML
    EDIT.

    Just ran it through Moz and found the cursor is at the end in both examples yet IE shows differently Bah!
    Last edited by Mr J; 05-24-2005 at 10:13 PM.
    The silent one.

    The most dangerous thing in the world is an idea.
    The most dangerous person in the world is the one with an idea.

  • #3
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    hehe, you get a cookie for the effort

    Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you're a mile away and you have their shoes :)

  • #4
    Regular Coder
    Join Date
    May 2005
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Internet Explorer

    It's not a "cursor", but a "caret".

    Code:
    <input value="blahblahblah" onfocus="(function(txt)
    {
    	if(!txt)
    		return;
    	(txt = txt()).collapse(false);
    	txt.select();
    })(createTextRange)">
    Not sure if that will escape error in non IE-compliant agents, but...
    Thanks in advance!

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <script>
    function set(id){
    	var txt = document.getElementById(id);
    	var txtValue = txt.value;
    	txt.focus();
    	txt.value = txtValue;
    	txt.focus();
    }
    </script>
    </head>
    
    <body onload="set('txt')">
    <input type="text" id="txt" name="txt" value="test">
    <input type="button" onclick="set('txt')" value="set caret to end">
    </body>
    </html>
    works in ie and mozilla.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #6
    Regular Coder
    Join Date
    May 2005
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Except with onfocus...
    Thanks in advance!

  • #7
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by enumerator
    Except with onfocus...
    i don't know what your talking about, in ie and mozilla it works.

    set it onload and you don't need onfocus.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #8
    Regular Coder
    Join Date
    May 2005
    Posts
    313
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's what I was talking about: "in ie and mozilla it works", except with onfocus. No big deal, just pointing out that it works only from an external event, so to speak...
    Thanks in advance!

  • #9
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, body onLoad="" works so w/e
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<

  • #10
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Quote Originally Posted by rlemon
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <script>
    function set(id){
    	var txt = document.getElementById(id);
    	var txtValue = txt.value;
    	txt.focus();
    	txt.value = txtValue;
    	txt.focus();
    }
    </script>
    </head>
    
    <body onload="set('txt')">
    <input type="text" id="txt" name="txt" value="test">
    <input type="button" onclick="set('txt')" value="set caret to end">
    </body>
    </html>
    works in ie and mozilla.
    That partially works in Firefox and probably in Moz too. If you set the caret anywhere but the end, the caret will not go to the end when the button is clicked. Tested it in Opera and didn't work at all.

    But you can minimize the code further. The important trick there is focusing first before setting the value.
    Code:
    function set(id){
    	var txt = document.getElementById(id);
    	txt.focus();
    	txt.value = txt.value;
    }
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #11
    Senior Coder
    Join Date
    Apr 2005
    Posts
    1,051
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yea, thats why I just stay away from setting the caret.

    Made a wysiwyg editor, had a ******* of a time to get that working properly. Still isn't perfect, but w/e.
    public string ConjunctionJunction(string words, string phrases, string clauses)
    {
    return (String)(words + phrases + clauses);
    }
    <--- Was I Helpfull? Let me know ---<


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •