Robert,
I'd like to prefill a text box in a form with a typical value, but
select the text, so that if the user begins typing, the prefilled text
is overwritten, wihtout him having to erase it. (Just like the
location bar in my browser - if I click on it, the text becomes
selected, so that one key overwrites the old location, without me
having to backspace.)
Can I do this with JQuery/JavaScript? How?
the autocomplete uses this code to select text, inspired (read: copied
and modified) by the field selection plugin (
http://lab.0xab.cd/jquery/fieldselection/ ):
jQuery.Autocompleter.Selection = function(field, start, end) {
if( field.createTextRange ){
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", end);
selRange.select();
} else if( field.setSelectionRange ){
field.setSelectionRange(start, end);
} else {
if( field.selectionStart ){
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
};
Disabling a submit button isn't too hard, with onchange/onblur you can
toggle its status. If you don't insist on disabling the submit button,
the form validation plugin may come in handy:
http://bassistance.de/jquery-plugins/jquery-plugin-validation/
--
Jörn Zaefferer
http://bassistance.de