Ya, this can get a bit tricky. First off, when creating javascript on the fly, "ClientID" is your friend. Every control has this property. It gives you the actual value of the id when rendered.
So what I would do is this. Setup your javascript in your aspx page with this:
document.getElementById('<%= GetUserControlClientID() %>')...
GetUserControlClientID() is the name of a method in your code behind. Feel free to rename the method. This method should return a string.
Inside the method call the UserControl's FindControl method to locate the control you're looking for. Then return the value of this control's ClientID property.
It should render correctly with the correct id in your javascript.