...

View Full Version : populate text field using onmouseover



rpjd
06-18-2010, 05:44 PM
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.


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?

Old Pedant
06-18-2010, 08:14 PM
I think you need to show *real* code.

This makes no sense:


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

document.FormName.FieldName.value =
or, if you prefer to be more modern,


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

document.getElementById("idOfField").value =

rpjd
06-19-2010, 08:34 PM
Thanks Old Pedant, got it working. I was using the table ID, not the form ID.
Cheers.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum