views:

22

answers:

1

Hi,

I have a table with links in the html document and they looks something like (first link is just javascript:):

javascript:

javascript:SelectField('{a guid}','2');return false;

javascript:SelectField('{a guid}','23');return false;

javascript:SelectField('{a guid}','1');return false;

javascript:SelectField('{a guid}','14');return false;

I want the number after the guid.

My current code is:

$("table").each(function(index, value) {
    $(this).addClass("table" + index);
});

var hrefs = new Array();
$('.table449').children().children().each(function(){
var link = ($(this).find('a').attr('href'));
var linkID = link.substring( link.indexOf(",'")+2, link.indexOf("');") )
hrefs.push(linkID);
alert(hrefs);
});

I get the values I want in an array but the first place is "j" (without ""). I guess it is because of +2 after the indexOf but how do I get rid of the j? I only want the numbers in the array.

Thanks in advance.

Edit: or is there a better way to get the ID's? edit2: the alert shows j,1,2,4,5,7,8,10 and so on

A: 
var startIndex = link.indexOf(",'");
var endIndex = link.indexOf("');");
if ( startIndex >= 0 && endIndex >= 0 ) {
    var linkID = link.substring( startIndex+2, endIndex );
    hrefs.push(linkID);
}
Fyodor Soikin
thanks Fyodor, first returned value is null though, how can I get rid of this?
Peter
reomove the >= and change it to just > on the startIndex >= 0
GerManson
Hi GerManson, unfortuneately it still returns null in the first place in the array. I guess I can just remove the first spot in the array though.
Peter