javascript to handle correctly actions