write function for checking checkbox when querying