...

View Full Version : Place cusor in first position of textbox?



eck35
12-19-2003, 06:24 PM
Greetings to All,

And of course many, many thank yous in advance.

Okay, how can I place the cursor in the first position of a textbox that already contains data using an onMousedown() event?

Any direction or input would be greatly appreciated.

Again, many thanks,

eck35

Kor
12-20-2003, 11:19 AM
nice question... At first glance I was tempted to say... just use focus() method... later I saw that, if onmousedown the cursor places whereever between the selected intial value characters...

Yet, I found out a phoney behaviour... If inserted an alert command, the cursor does place at the begining... This might not be a good answer to your question, but it might help you somehow...



<html>
<head>
<script>
function bla(){
document.forms[0].text.focus();
alert('oak');
}
</script>
</head>
<body>
<form>
<input name ="text" type="text" value="oak" onmousedown="bla()">
</form>
</body>
</html>

Willy Duitt
12-20-2003, 05:08 PM
Originally posted by Kor
nice question... At first glance I was tempted to say... just use focus() method... later I saw that, if onmousedown the cursor places whereever between the selected intial value characters...

Yet, I found out a phoney behaviour... If inserted an alert command, the cursor does place at the begining... This might not be a good answer to your question, but it might help you somehow...



<html>
<head>
<script>
function bla(){
document.forms[0].text.focus();
alert('oak');
}
</script>
</head>
<body>
<form>
<input name ="text" type="text" value="oak" onmousedown="bla()">
</form>
</body>
</html>


To do this (leave default value but place cursor prior) you can also use reset()

EG:

<form>
<input name ="text" type="text" value="oak" onfocus="reset();">
</form>

Or to remove the default value:

<html>
<head>
<script>
function bla(){
document.forms[0].text.value='';
}
</script>
</head>
<body>
<form>
<input name ="text" type="text" value="oak" onmousedown="bla();">
</form>
</body>
</html>

....Willy

Edit: Changed onmousedown back to onfocus.
Sorry, I was using onfocus, then seen the op requested
onmousedown. Changed it and then realized that didn't work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum