fixed function, now alert works, but error msg always same