If a user types the correct word a function should be called. Currently i have this jQuery Snippet
..
<input type="text" id="code" name="code" placeholder="code">
...
<script>
$(function () {
var discountCode = 'test4';
var codeEntered = $("input[name='code']").val();
$("#subbtn").on("click", function () {
if (discountCode == codeEntered) {
alert("RIGHT!");
} else {
alert("WRONG!");
}
});
});
</script>
But i get always "WRONG" even if i type "test4". What do i wrong ?