Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-20-2012, 02:18 PM   PM User | #1
kevvo
New to the CF scene

 
Join Date: May 2012
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
kevvo is an unknown quantity at this point
Extracting data from table columns

Hi there,

I am trying to extract all of the values from the 5th column (Assignee) in this HTML table http://bugzilla.maptools.org/buglist...icksearch=test and don't know how to proceed.

Is there a clever way of getting the entire col class: <col class="bz_op_sys_column"> before putting into an array.

thanks, kev
kevvo is offline   Reply With Quote
Old 05-20-2012, 02:40 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
from what I understand of html tables (and that's not much because I don't really like them), there is no column as such - there are only rows which have cells and the cells line up to appear like columns.

But you can count which cell number you are interested in and search for that in each row, something like this (provided your table has an id):

Code:
var emails=[]
function getEmails() {
tab=document.getElementById("thetable")
  for (var i = 1; i < tab.rows.length; i++) {
  emails.push(tab.rows[i].cells[4].innerHTML)
		}
  }
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
kevvo (05-20-2012)
Old 05-20-2012, 02:50 PM   PM User | #3
Peeyush
Regular Coder

 
Join Date: Apr 2012
Posts: 104
Thanks: 27
Thanked 2 Times in 2 Posts
Peeyush is an unknown quantity at this point
i dont think you can get data by javascript which resides in another server. I have tried to do it once. Anyway i didnt try this method so you can try using getElementById method. I.e. var webdoc = //link of the html page
webdoc.getElementById('id') ;

that way. Bt i do think you cant get it if its on other server
__________________
Everything is simpler with jQuery!
Peeyush is offline   Reply With Quote
Users who have thanked Peeyush for this post:
kevvo (05-20-2012)
Old 05-20-2012, 02:58 PM   PM User | #4
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
oh, sorry - I missed that one. Peeyush is right - if that isn't your page, you can't get at the info using javascript
xelawho is offline   Reply With Quote
Old 05-20-2012, 03:14 PM   PM User | #5
kevvo
New to the CF scene

 
Join Date: May 2012
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
kevvo is an unknown quantity at this point
Thanks for the replies.

I should have mentioned that I am creating a Greasemonkey script that will handle the extraction using javascript. Does that change anything?

thanks again guys

Last edited by kevvo; 05-20-2012 at 03:15 PM.. Reason: typo
kevvo is offline   Reply With Quote
Old 05-20-2012, 03:38 PM   PM User | #6
kevvo
New to the CF scene

 
Join Date: May 2012
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
kevvo is an unknown quantity at this point
Also, how can i getelementbyid when the table has no ID? Is there a way to "add in" an ID to the table?
kevvo is offline   Reply With Quote
Old 05-20-2012, 04:09 PM   PM User | #7
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
no, you can't insert IDs, and to be honest this thing is looking less likely as it goes on.

But in general if an element has no other identifying feature you can find it according to its location in the DOM, although here you have to be careful because to me it seems that IE counts nodes differently to other browsers. Here's what it would be in Firefox, anyway:
Code:
tab=document.body.childNodes[3].childNodes[7]
xelawho is offline   Reply With Quote
Users who have thanked xelawho for this post:
kevvo (05-20-2012)
Old 05-20-2012, 04:15 PM   PM User | #8
kevvo
New to the CF scene

 
Join Date: May 2012
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
kevvo is an unknown quantity at this point
I appreciate your honesty. Thankfully I don't need to worry about IE as i'll only be using this myself. All i need to be able to do is collect all the information from the assignee column into an array from the table i linked above, but because the table has no ID, im stuck big time. thanks again
kevvo is offline   Reply With Quote
Old 05-20-2012, 04:23 PM   PM User | #9
Peeyush
Regular Coder

 
Join Date: Apr 2012
Posts: 104
Thanks: 27
Thanked 2 Times in 2 Posts
Peeyush is an unknown quantity at this point
@xelawho, cant we add id using js if its his page
i.e
Code:
 
var a = document.getElementsByTagName("table").[some number]

a.id='idYouWantToAdd'
i have used this before i think we can add id.



Btw @kevvo thanks for thanking me. Its 1st time some one has thanked my post
__________________
Everything is simpler with jQuery!

Last edited by Peeyush; 05-20-2012 at 04:28 PM..
Peeyush is offline   Reply With Quote
Old 05-20-2012, 04:38 PM   PM User | #10
kevvo
New to the CF scene

 
Join Date: May 2012
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
kevvo is an unknown quantity at this point
@Peeyush - i always give credit where credit is due.

Maybe i am just bad at explaining what i am trying to achieve here. For work, I need to build an array of all the data stored in the Assignee column (column number 4) on this page http://bugzilla.maptools.org/buglist...icksearch=test

I can't modify the page itself, that's why i'm creating a greasemonkey script using javascript to build the array for me once the page is loaded. Sort of like injecting the js into the page once it finishes loading it.
kevvo is offline   Reply With Quote
Old 05-20-2012, 04:49 PM   PM User | #11
kevvo
New to the CF scene

 
Join Date: May 2012
Posts: 8
Thanks: 3
Thanked 0 Times in 0 Posts
kevvo is an unknown quantity at this point
Here is what I have come up with.

Code:
for(var i=0;i<document.getElementsByTagName('*').length;i++){
if(document.getElementsByTagName('*')[i].className == 'bz_assigned_to_column'){
document.getElementsByTagName('*')[i].style.backgroundColor = 'red';
}
}
If you run this code after the page loads you will see that I am able to get the first cell in the column to change color.
How do i do this for the entire column?

kev.
kevvo is offline   Reply With Quote
Old 05-20-2012, 05:10 PM   PM User | #12
Peeyush
Regular Coder

 
Join Date: Apr 2012
Posts: 104
Thanks: 27
Thanked 2 Times in 2 Posts
Peeyush is an unknown quantity at this point
hey. Sorry, I had no idea of what you meant by greasemonkey scripts. Now i hav read a little about them on wikipedia. If you are able to change color of 1 cell, i am sure that it can be done for whole column using loops and DOM. Currently i am browsing on mobile so i wont be able to help much.
__________________
Everything is simpler with jQuery!

Last edited by Peeyush; 05-20-2012 at 05:46 PM.. Reason: punct.uatio,n
Peeyush is offline   Reply With Quote
Reply

Bookmarks

Tags
column, table

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:52 AM.


Advertisement
Log in to turn off these ads.