simplify code by using javascript confirm function