I'm unclear about the different methods of selecting a portion of a
text input .. I'm testing with firefox 2 first. Any ideas?
jQuery.fn.valSel = function(val,start, end){
var field = this
field.val(val)
var m = ""
if (field.createTextRange) {
var selRange = field.createTextRange()
selRange.collapse(true)
selRange.moveStart("character", start)
selRange.moveEnd("character", - end + start)
selRange.select();
m = "ie"
} else if (field.setSelectionRange) {
field.setSelectionRange(start, end)
m = "1"
} else if (field.selectionStart || field.selectionStart == '0'){
field.selectionStart = start
field.selectionEnd = end
m = "2"
}
jQuery.log(m + ":" + val + "," + start+ "," + end)
return field.focus();
}
it sets the val, and passes the start and end in... but none of the
different 'if's are fired... Any ideas? I'm using it on a simple field
<input name="city-state" tabindex="5" value="" maxlength="20"
size="20" type="text">
I borrowed most of it from iautocompleter from interface plugin
selection : function(field, start, end)
{
if (field.createTextRange) {
var selRange = field.createTextRange();
selRange.collapse(true);
selRange.moveStart("character", start);
selRange.moveEnd("character", - end + start);
selRange.select();
} else if (field.setSelectionRange) {
field.setSelectionRange(start, end);
} else {
if (field.selectionStart) {
field.selectionStart = start;
field.selectionEnd = end;
}
}
field.focus();
},
--
Ⓙⓐⓚⓔ - יעקב ʝǡǩȩ ᎫᎪᏦᎬ
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/