Javascript confirm multiple changes -
i want alert user changes made in 4 fields. script works 1 @ time. if 1 or 4 changes have been made, alerts first 1 , skips others. displayed in 1 confirm box.
<script> function validateform() { var w = document.getelementbyid("item_name"); if (w.value != w.defaultvalue) { return confirm('update item name. continue?'); } var x = document.getelementbyid("item_brand"); if (x.value != x.defaultvalue) { return confirm('update item brand. continue?'); } var y = document.getelementbyid("department_id"); if (!y.options[y.selectedindex].defaultselected) { return confirm('update item department. continue?'); } var z = document.getelementbyid("vendor_part_num"); if (z.value != z.defaultvalue) { return confirm('update vendor part number. continue?'); } } </script>
you don't want ask each field individually, first check them all, ask user, this
<script> function validateform() { var strquestion = ''; var bstchanged = false; var w = document.getelementbyid("item_name"); if (w.value != w.defaultvalue) { bstchanged = true; strquestion = strquestion + 'update item name.' + string.fromcharcode(13); } var x = document.getelementbyid("item_brand"); if (x.value != x.defaultvalue) { bstchanged = true; strquestion = strquestion + 'update item brand.' + string.fromcharcode(13); } var y = document.getelementbyid("department_id"); if (!y.options[y.selectedindex].defaultselected) { bstchanged = true; strquestion = strquestion + 'update item deparment.' + string.fromcharcode(13); } var z = document.getelementbyid("vendor_part_num"); if (z.value != z.defaultvalue) { bstchanged = true; strquestion = strquestion + 'update vendor part number.' + string.fromcharcode(13); } if (bstchanged) { return confirm(strquestion + ' continue?') } } </script>
Comments
Post a Comment