I tried the same thing... the id's are generated when the page loads, but code in the script library does not get executed. So, one way around it is to calculate the id's in the page and then pass those id's as parameters of the function in the script library.