I'm trying to implement a simple anti-spam field on my form where the server generates a random string, sends it to the user, and then JavaScript reverses the string before submitting it. If the string doesn't match, the submission is discarded as spam. The issue is that I can't seem to get JavaScript or jQuery to reverse the input value.
$(document.ready(function() {
var reverse = $('#simple').val().split("").reverse().join("");
document.getElementById('simple').setAttribute('value', reverse);
}))
Using
$('#simple').val(reverse);
instead of the setAttribute method also fails.
The input field itself is:
<input type="text" id="simple" name="simple" value="abcde" />
jQuery is being included and I can get the input value to reverse if I type in the same code via the developer tools console, but the page itself doesn't work. Thanks!