[thelist] js cursor position in a form

Peter Brunone (EasyListBox.com) peter at easylistbox.com
Thu Jan 5 10:35:13 CST 2006

Okay, I understand how that goes.  Just for the record, though, this script seemed to work (added an extra space and selected it for the first keystroke) -- go figure:

function populaterep() {    var theform = document.getElementById("frmdefault");
var oRange = theform.repid_number.createTextRange();    if (theform.office_code.value!="")
theform.repid_number.value = theform.office_code.value + " ";    oRange.moveStart("character", 4);

   Also, FYI, I never got any errors, even when I pasted your code and ran it as-is (with appropriate script and head/body tags, of course).



 From: Brian Cummiskey Brian at hondaswap.com

Peter Brunone (EasyListBox.com) wrote:
> Without knowing the line that triggers the error, I can't say for sure 
> what the problem is, but I'd recommend creating the textRange *after* 
> you fill the field.

var oRange = theform.repid_number.createTextRange();

that's the error line.

I've had it in both places-- where it is now, and right after i fill the 
field with theform.repid_number.value = theform.office_code.value;

When its inside there, it doesn't throw an error, but it also doesn't do 

> Also, you should call select on oRange, not on the field itself.

had it that way too, and the field didn't get selected.

the way i have it now, it at least highlights the whole field.

I don't know, i'm probably just going to scrap the idea. I've already 
spent too much time on this, and I thought it would be a neat feature-- 
not a requirement.

Thanks for taking the time to help.

More information about the thelist mailing list