Hi,
I seem to be struggling to find a solution of being able to limit user input in a textarea field while keeping the 'caret' (cursor position) in the correct place.
I have searched high and low and tried to implement the JQuery 'caret' plugin, but with no success.
If I use the followng...
If I press enter , it moves the caret to the end of the last line above the carriage return?
If I don't try to calculate the position, and I edit some text in the middle of the textarea content, it keeps moving the caret to the end of the content.
I appreciate that as I am replacing the content 'onkeyup' using a regex, that this will move the cursor to the end, but using the JQuery 'caret' plugin doesn't work with the enter key?
I guess I'm doing something wrong or need a different method and hope you can enlighten me.
Cheers,
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
MIME::Lite TLS Email Encryption - Perl v0.02 beta
I seem to be struggling to find a solution of being able to limit user input in a textarea field while keeping the 'caret' (cursor position) in the correct place.
I have searched high and low and tried to implement the JQuery 'caret' plugin, but with no success.
If I use the followng...
Code:
var chkField = $('#editBox');
mycursorpos = chkField.caret().end;
var len1 = chkField.val().length;
chkField.val(chkField.val().replace(/[^0-9 a-z\'\\\/\:\;\-\+\.\?\!\*\(\)\_\& \,\r\n]/gi, ''));
var len2 = chkField.val().length;
if(len1 != len2){
mycursorpos--;
}
chkField.caret({start:mycursorpos,end:mycursorpos});
If I press enter , it moves the caret to the end of the last line above the carriage return?
If I don't try to calculate the position, and I edit some text in the middle of the textarea content, it keeps moving the caret to the end of the content.
I appreciate that as I am replacing the content 'onkeyup' using a regex, that this will move the cursor to the end, but using the JQuery 'caret' plugin doesn't work with the enter key?
I guess I'm doing something wrong or need a different method and hope you can enlighten me.
Cheers,
1DMF
"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
MIME::Lite TLS Email Encryption - Perl v0.02 beta