...

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



canadianjameson
11-10-2004, 03:12 AM
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|

hemebond
11-10-2004, 03:57 AM
<!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>

canadianjameson
11-10-2004, 05:39 AM
whats with you and your random titles?

hehe :D

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

:o

hemebond
11-10-2004, 06:25 AM
What random titles? I don't usually have titles for my posts.
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.
<!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>

canadianjameson
11-10-2004, 03:46 PM
doesnt seem to work in I.E 6

hemebond
11-10-2004, 09:33 PM
IE doesn't support setSelectionRange. Or any selection functions on elements.

canadianjameson
11-10-2004, 11:11 PM
so basically this'll work in any browser except i.e?

hemebond
11-11-2004, 02:47 AM
No, just Gecko browsers.

canadianjameson
11-11-2004, 04:02 AM
and there is no way to do it it most major browser like I.E?

fci
11-11-2004, 04:08 AM
I don't have IE, but here is the documentation which will probably point you in the right direction:
http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_textrange.asp
http://msdn.microsoft.com/workshop/author/dyncontent/textrange.asp

canadianjameson
11-11-2004, 04:58 AM
would this be usefull?

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/obj_textrange.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum