There is a textbox in your webpage and you want to submit form only if the textbox’s value has changed else you want tol show some validation message.
But how to do it? One approach would be to take a hidden field along with the textbox which keeps the textbox’s default value and on clicking the button we compare the default value with the changed value and if it does not match then only we consider that the textbox’s value has changed.
It looks very simple but the demerit is that if you have more than one textbox in your page then you have to take that many number of hidden fields, which is not a good idea. So how to do it using a better approach?
There is another simple approach by which we can do it.
In the following example I have taken a textbox and a button and on button click I am accessing the Textbox’s previous value as well as its current value. On page load the textbox will contain ‘Devi Das’, if we change the value to ‘Deviprasad Das’ and click on the button then it would show the alert message –
“Previous Value: Devi Das, Current Value: Deviprasad Das”, which indicates that the value of the textbox has changed.