Bug fixing to find the selected element in a select