Monday, April 21, 2014

Java 8 Features:

Look inside >
5
JAVA EXPLORE THE POSSIBILITIES

Wednesday, April 9, 2014

How to know Textbox's value has changed or not?

Problem
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.
Solution
A JavaScript property known as 'defaultValue' is available by which you can know what was the default value of the textbox.
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: Sample Text, Current Value: Sample Text Changed", which indicates that the value of the textbox has changed.

<html>
<head>
<script type="text/javascript">
    function checkValue()
    {
        var objName = document.getElementById("txtName");
        alert("Previous Value: " +
objName.defaultValue + ", Current Value: " + objName.value);
    }
</script>
</head>
<body>
    <input type="text" id="txtName" value="
Sample Text" />
    <input type="button" onClick="checkValue();" value="Check" />
</body>
</html>
  Reference