mr_burns wrote:
How do I then
make the cursor be placed at the end of the text.
Some helpfull functions:
function setSelectedTextRange(elm, selectionStart, selectionEnd) {
if (elm.setSelectionRange) {
elm.focus();
elm.setSelectionRange(selectionStart, selectionEnd);
}
else if (elm.createTextRange) {
var range = elm.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function setCaretToEnd (elm) {
setSelectedTextRange(elm, elm.value.length, elm.value.length);
}
function setCaretToStart (elm) {
setSelectedTextRange(elm, 0, 0);
}
function setCaretToPos (elm, pos) {
setSelectedTextRange(elm, pos, pos);
}
Use it like this:
var iField = document.getElementById("inputfield");
iField.value = "foobar";
setCaretToPos(iField,3);
//or
setCaretToEnd(iField);
Or in your case:
<input name="txt_url" type="text" class="form_text_300" id="txt_url"
onClick="if(this.value == ''){this.value = 'http://';setCaretToEnd(this);}">
Daniel