-1

I need to create a code in HTML/Javascript that will allow a user to enter an answer to a maths question and then the site needs to validate whether that answer is correct.

Been playing around for a few hours and researched the web but not found anything close.

Any help is appreciated!!

hooknc
  • 4,854
  • 5
  • 31
  • 60
  • "Been playing around for a few hours" can you provide the code you've been playing around so that it is easy for the community to provide a relevant answer..? – T J May 21 '14 at 18:40

2 Answers2

0

You could use javascript for validation,

Look at this example.

var value = Number(intfield.value);
if (Math.floor(value) == value) {
    // value is an integer, do something based on that
} else {
    // value is not an integer, show some validation error
}

checking if value of a textfield is integer in javascript

Community
  • 1
  • 1
MjZac
  • 3,476
  • 1
  • 17
  • 28
0

Javascript validation

function isInteger(number) {
    var getVal = parseInt(number);
    if (number.length == 0 || getVal == Number.NaN || getVal <= 0) {
        return false;
    }
    return true;
}
MH2K9
  • 11,951
  • 7
  • 32
  • 49