Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts

    populate text field using onmouseover

    I have a table where when the cursor passes/hovers over a cell, the current cell, as well as the top cell in its column and the first cell in its row change backgroundColor. I have text fields outside the table which I want to populate with the contents of the cells affected by the mouseover event. So as the mouse moves over different cells, the contents of the text fields changes accordingly. I've got the backgroundColor to change, but when I try to assign the contents of the cells to the text fields, nothing happens. The change of backgroundColor even stops working.
    This is the code I'm usign to populate the fields.
    Code:
    document.getElementById("tableID").textfieldID.value = Col1Cell[0].innerHTML;
    document.getElementById("tableID").textfieldID.value = HeaderCell[n].innerHTML;
    document.getElementById("tableID").textfieldID.value = this.innerHTML;
    I'm traversing through the <th> and <td> tags to find the header cell HeaderCell[n] and first column cell Col1Cell[0] associated with the current cell. If I leave out these lines the backgroundColor changes, if I use them, nothing happens at all. Can't figure out why. Any suggestions?

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,596
    Thanks
    80
    Thanked 4,633 Times in 4,595 Posts
    I think you need to show *real* code.

    This makes no sense:
    Code:
    document.getElementById("tableID").textfieldID.value =
    You are getting a reference to a <table>??? Is that what "tableID" means?

    If so, then why would you expect to be able to get a reference to a <form> field inside that <table> using that format??

    *Normally*, to reference a form field, you would use
    Code:
         document.FormName.FieldName.value =
    or, if you prefer to be more modern,
    Code:
        document.getElementById("idOfForm").FieldName.value =
    In any case, notice that you use the *name* of the field, no the ID.

    If you assign both names and ids to your form fields, then you don't need a reference to the form, at all. Just
    Code:
         document.getElementById("idOfField").value =
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks Old Pedant, got it working. I was using the table ID, not the form ID.
    Cheers.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •