• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Javascript gurus, need some help..

aceO07

Diamond Member
I don't know much javascript. I used to know some dom, but I've forgotten most of it.

The goal is to have a table, with information cells. When a user clicks on a cell, it will trigger js that will pull attributes from that cell and populate it into another element on the same page.

example:
(table)
(tr) (td row='row15' col='col5') Sunny (/td)
(td row='row15' col='col6') Cloudy (/td)(/tr)
(/table)

(form)
(input id='row' type=hidden name='row' value=)
(input id='col' type=hidden name='col' value=)
(/form)

Based on my example, I'd like to be able to click on a cell and have js extract the row and col attributes from the (td) cell and write to the the hidden inputs for the form, which is on the same page.

I know it's possible and I am currently search for it, however it's be great if someone told me the answer before I got to it myself.
 
oh wait, my bad. what you want is actually even simpler.

sorry here is what you really wanted:

edit: i have no idea what the code box thing scrunches all the text together- wtf?

i copy + paste formatted text out of notepad++ into it and it loses all formatting- whitespace, line breaks, indenting...
 
Thanks lozina, I'm actually getting it now myself too. Thanks also for the getAttribute method reference. Before I was trying to use the .id reference and had to concatenate the col/row into the id attribute, which I'd have to extract later.

I think I'll use the behaviour.js (http://www.bennolan.com/behaviour/) to handle the onclick for each cell. The tables I'll be putting this code onto will have over 100 cells, though sometimes less. All the onclick hooks to each cell might take up quite a bit of space.
 
I've become a jquery whore.

$("#tdID").clicked(function() {
$("#fieldID").val($this.html());
});

or something like that, i'm really tired.

 
That's interesting. I'll look into jquery at some point, though I'm not really a web dev person. I just happen to be on a project where I am doing it now.

I'm using Behaviour.js to listen to any clicks based on rules that I can set for any ID or class of an element. I just state the rule once, and put in the right identifiers in the elements and it knows what to do. Saves me from doing a onclick for each cell. I see that jquery would let me do the same, but unfortunately the jquery file is 94Kb. Behaviour.js is only 8Kb, and really 5.4Kb once I strip out the author comments and just leave the author info etc. Trying to cut down on size. If I knew enough js to minimize prototype.js I would since I'm sure I don't need everything it provides.
 
Back
Top