DOM: Form Field Position

Discussion in 'Water Cooler' started by Wayne Luke, Jun 14, 2009.

  1. Wayne Luke

    Wayne Luke Regular Member

    Apr 2, 2009
    Likes Received:
    Okay, maybe someone here can help with this. What I want to do is find all input fields on a page and under specific circumstances show an image immediately to the left. I want to do this with the DOM and Javascript without any HTML edits.

    I know about object.offsetTop and object.offsetLeft but they aren't being referenced properly. It always references 0,0 of the screen and shows relatively to that. I want to it show relatively to the field itself.

    The code in question is this:
    show_warning: function(targ) {
    if (!targ.warning) {
    targ.warning = document.createElement('img');
    targ.warning.src = "images/misc/arrow_up.png"; = "absolute"; = (targ.offsetTop) + "px"; = (targ.offsetLeft + targ.offsetWidth - 5) + "px"; = "999";
    targ.warning.setAttribute("alt", "Warning: Caps Lock is on");
    if (targ.warning.runtimeStyle) {
    // PNG transparency for IE
    targ.warning.runtimeStyle.filter +=
    Original article is here:
    24 ways: Capturing Caps Lock

    Some pages might have more than one password field.

Share This Page