Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-24-2005, 09:55 PM   PM User | #1
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
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 :)
canadianjameson is offline   Reply With Quote
Old 05-24-2005, 10:09 PM   PM User | #2
Mr J
Senior Coder

 
Join Date: Aug 2002
Location: UK
Posts: 2,789
Thanks: 2
Thanked 14 Times in 14 Posts
Mr J is on a distinguished road
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!
__________________
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.

Last edited by Mr J; 05-24-2005 at 10:13 PM..
Mr J is offline   Reply With Quote
Old 05-24-2005, 10:58 PM   PM User | #3
canadianjameson
Senior Coder

 
Join Date: Jul 2003
Location: My pimped-out igloo in Canadia
Posts: 1,966
Thanks: 36
Thanked 0 Times in 0 Posts
canadianjameson is an unknown quantity at this point
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 :)
canadianjameson is offline   Reply With Quote
Old 05-25-2005, 03:27 AM   PM User | #4
enumerator
Regular Coder

 
Join Date: May 2005
Posts: 313
Thanks: 0
Thanked 0 Times in 0 Posts
enumerator is an unknown quantity at this point
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!
enumerator is offline   Reply With Quote
Old 05-25-2005, 03:46 AM   PM User | #5
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
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 ---<
rlemon is offline   Reply With Quote
Old 05-25-2005, 03:58 AM   PM User | #6
enumerator
Regular Coder

 
Join Date: May 2005
Posts: 313
Thanks: 0
Thanked 0 Times in 0 Posts
enumerator is an unknown quantity at this point
Except with onfocus...
__________________
Thanks in advance!
enumerator is offline   Reply With Quote
Old 05-25-2005, 04:52 AM   PM User | #7
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
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 ---<
rlemon is offline   Reply With Quote
Old 05-25-2005, 05:22 AM   PM User | #8
enumerator
Regular Coder

 
Join Date: May 2005
Posts: 313
Thanks: 0
Thanked 0 Times in 0 Posts
enumerator is an unknown quantity at this point
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!
enumerator is offline   Reply With Quote
Old 05-25-2005, 06:33 AM   PM User | #9
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
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 ---<
rlemon is offline   Reply With Quote
Old 05-26-2005, 05:55 AM   PM User | #10
glenngv
Supreme Master coder!


 
glenngv's Avatar
 
Join Date: Jun 2002
Location: Los Angeles, CA Original Location: Philippines
Posts: 10,241
Thanks: 0
Thanked 112 Times in 111 Posts
glenngv will become famous soon enough
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
_____________________________________________
Play Tower of Hanoi Android app (Ad-FREE!)
Play Tower of Hanoi Android app (FREE!)
Go to Tower of Hanoi Leaderboard
Play Tower of Hanoi Facebook app
glenngv is offline   Reply With Quote
Old 05-26-2005, 03:55 PM   PM User | #11
rlemon
Senior Coder

 
Join Date: Apr 2005
Posts: 1,051
Thanks: 0
Thanked 0 Times in 0 Posts
rlemon is on a distinguished road
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 ---<
rlemon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:46 PM.


Advertisement
Log in to turn off these ads.