The last HTML5 input field before a form's submit button is a spam filter asking the user to solve a simple algebraic equation that resolves to 4 before submitting the form to a separate page for php processing. The input field (type=number, name=ebot) watches for an onchange event and if detected calls a function. When I entered an invalid value and clicked 'submit' the form passed to php.
I then stripped down the function as indicated below to find out why.
function chkEvent() {
var elemValue = document.forms['eFields']['eBot'].value;
alert(elemValue);
}
Now entering anything into the input field (ebot) confirmed three (3) things:
- clicking submit fired ebot's onchange event and stopped the submit process
- the onchange event called the function chkEvent
- the alert box correctly displayed the user-entered value
I then restored chkEvent's original structure.
function chkEvent() {
var elemValue = document.forms['eFields']['eBot'].value;
if(elemValue <> 4) {
document.eFields.esubmit.disabled=true;
alert("Please solve correctly for x.");
} else {
document.eFields.esubmit.disabled=false;
}
}
Now, regardless of what is entered in the spam filter, the form passes to php when submit is clicked. The same behavior exhibits in Chrome, Firefox, and IE. I may have stared at this for too long but please, no non-JavaScript suggestions. Time constraints prevent me learning a new language.
I've often benefitted from the tremendous skill and expertise on this forum. Thanx everyone !!
if(elemValue <> 4) {
toif(elemValue == 4) {
or perhaps changing the4
to'4'
I believe the type returned from a text input is a string, not an integer, so you could be running into a type issue there. – BrianelemValue !== '4'
. – JLRishe