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

    is there a way to set form field text and put the cursor after it?

    if i have a form field with the first part of the text filled out, such as having this:

    Whats your login id:
    4519.....

    if all id's start with 4519, can i set that as the default field text (yes), AND have the cursor focus() AFTER the 9?

    i.e if this is my cursor: |
    instead of it doing this
    |4519
    can it do this?
    4519|
    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
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>47276</title>
    	</head>
    	<body>
    		<form>
    			<fieldset>
    				<input id="txt" type="text" value="value">
    			</fieldset>
    		</form>
    	</body>
    	<script type="text/javascript">
    		document.getElementById("txt").focus();
    	</script>
    </html>

  • #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
    whats with you and your random titles?

    hehe

    ummm, hemebond. although perhaps a good alternative way to set the focus in a particular field (apart from the standard onload).... this script you've provided does not put the cursor at the end of "value|"

    which is what i would like it to do.

    this puts it at the start of it |value

    Last edited by canadianjameson; 11-10-2004 at 04:43 AM.
    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
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    What random titles? I don't usually have titles for my posts.
    Quote Originally Posted by canadianjameson
    this script you've provided does not put the cursor at the end of "value|"
    What browser are you using, because it does in mine.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html lang="en">
    	<head>
    		<title>47276</title>
    	</head>
    	<body>
    		<form>
    			<fieldset>
    				<input id="txt" type="text" value="value">
    			</fieldset>
    		</form>
    	</body>
    	<script type="text/javascript">
    		var txt = document.getElementById("txt");
    		txt.focus();
    		txt.setSelectionRange(txt.value.length, txt.value.length);
    	</script>
    </html>

  • #5
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    doesnt seem to work in I.E 6
    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 :)

  • #6
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    IE doesn't support setSelectionRange. Or any selection functions on elements.

  • #7
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    so basically this'll work in any browser except i.e?
    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 :)

  • #8
    Senior Coder
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    1,315
    Thanks
    0
    Thanked 2 Times in 2 Posts
    No, just Gecko browsers.

  • #9
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    and there is no way to do it it most major browser like I.E?
    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 :)

  • #10
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't have IE, but here is the documentation which will probably point you in the right direction:
    http://msdn.microsoft.com/workshop/a..._textrange.asp
    http://msdn.microsoft.com/workshop/a.../textrange.asp

  • #11
    Senior Coder
    Join Date
    Jul 2003
    Location
    My pimped-out igloo in Canadia
    Posts
    1,966
    Thanks
    36
    Thanked 0 Times in 0 Posts
    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 :)


  •  

    Posting Permissions

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