2D DHTML Object Drawing JavaScript library
Caret/cursor position in INPUT text field or TEXTAREA
The following JavaScript method determines the current caret
position for the passed input text field or textarea. The code is IE specific. Tested for IE 6.
function caretPosition(textfield) {
textfield.focus();
if (textfield.type == 'textarea') {
var range = document.selection.createRange();
var range2 = range.duplicate();
range2.moveToElementText(textfield);
var bookmark = range.getBookmark();
var bookmark2 = range2.getBookmark();
return bookmark.charCodeAt(2) - bookmark2.charCodeAt(2);
} else { // Assume input field of type text
var range = document.selection.createRange();
range.moveStart ('character', -textfield.value.length);
return range.text.length;
}
}
Thanks, Mihai, for the bookmark trick. (See
http://www.bazon.net/mishoo/articles.epl?art_id=1292)
JavaScript Widgets
A great looking JavaScript widgets library (commercial):
http://www.activewidgets.com/
Web Page Printing
In the stylesheet:
@media print {
.noprint {display: none;}
.contentwidth1000 {width: 100%;}
}@media screen {
.contentwidth1000 {width: 1000;}
}In your HTML code, hide stuff on the printout like:
<div class="noprint">
…
</div>
An A4 page is only about 640 pixels wide (default IE margins). Thus you may have to adjust the width of certain elements. For example, instead of:
<td width="1000">...</td>
Do it like this:
<td class="contentwidth1000">...</td>
For the actual printing, use a link like:
<a href="#" onClick="window.print(); return false">Print</a>