|
-
Jan 17th, 2005, 09:22 AM
#1
Thread Starter
Junior Member
Set a Textbox cursor to the end?!?!?
Hi,
I have a bit of script that I am using to set focus back onto a textbox but when I use it, the cursor is always at the beginning of the text but I need it to be at the end. Does anyone know how to do this?
Code:
Dim strBuilder As String strBuilder = "<script language = 'javascript'>"
strBuilder = strBuilder & "document.forms.Form1.txtSearch.focus();"
strBuilder = strBuilder & "</script>"
RegisterStartupScript("Focus", strBuilder.ToString)
That's my code to set the focus back on the text box. Any help is appreciated!
Thanks in advance!!
-
Jan 18th, 2005, 10:15 AM
#2
Frenzied Member
Re: Set a Textbox cursor to the end?!?!?
You want to use the various range methods. Here is some code that I was playing around with when I was trying out some of the same things. Take a look at the EOT function.
Code:
<html>
<head>
<script type="text/javascript">
function EOT(txt)
{
var range = txt.createTextRange();
range.move("textedit");
range.select();
}
function EOW(txt)
{
var range = txt.createTextRange();
range.move("word", 2);
range.select();
}
</script>
</head>
<body onload="document.frm.vanilla.select()";>
<form name="frm">
<textarea cols="80" rows="4" wrap="soft">Testing plain vanilla textarea block</textarea>
<br /><br />
<textarea cols="80" rows="4" wrap="soft" onfocus="EOT(this);">Testing EOT in a textarea block</textarea>
<br /><br />
<input type="text" size="50" value="Testing EOT in an input block" onfocus="EOT(this);">
<br /><br />
<input type="text" size="50" value="Testing plain vanilla input block" name="vanilla">
<br /><br />
<input type="text" size="50" value="Testing EOW in an input block" onclick="EOW(this);">
<br /><br />
<input type="text" size="50" value="Testing clear on select" onfocus="this.value = '';">
<br /><br />
<input type="text" size="50" value="Testing highlight all on select" onfocus="this.select();">
</form>
</body>
</html>
You may also want to look at some of the other '1st parameter' values for the .move method.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|