If you would like┬áto prevent a select box from being changed if not confirmed by user. So here the case is before changing select option , user will be get a message as javascript confirmation to make sure user is ready to change dropdown else select option won’t be changed and will be as it is. So here question comes, how can we will do this ? Because change event is only triggered once the value of the select option has actually been changed. But I have the solution which confirm change event on confirmation for a dropdown and provides exact solution like if will click ok then your option will be changed else if you click cancel then your option won’t be changed.

confirm change event on confirmation for a dropdown
confirm change event on confirmation for a dropdown

For this type of criticality I am not using any jquery , I juts have done through simple javascript for avoiding to include any library files like jQuery and that is managed through two variables like old and new. So if user confirms then old value will be replaced by new value else current value will be still same old value. please look to the below javascript code that I have done.

so take our full example to make sure our logic is working and to make us fully understandable that how all works.

Live Demo


Click To Run

Hope You enjoy this article

confirm change event on confirmation for a dropdown
The following two tabs change content below.
Jyotiranjan is one of passionate programmer who has been working in magento since 4 years and in the mean time he has developed enormous amount of modules and customization of sites.He loves to write blogs and travel for long journeying.
Tagged on:             

Leave a Reply

Your email address will not be published. Required fields are marked *