Fix bugs in search by date javascript