modified query, corrected javascrpt error