I have an Ajax call that loops through a json file with the following code:
It calls a function in the form tag as follows:
When I try to validate the quantity to make sure that it’s a positive number less than ten, I use the following javascript:
function myFunction() {
var x;
x = document.getElementById(‘numb’).value;
alert(x);//this prints 0 every time
if ( isNaN(x) || (x < 0) || (x > 10)) {
alert(“Quantity must be a positive number less than 10.”);
event.preventDefault();
return false;
} else {
alert(“Input OK”);
}
}
The problem is that it doesn’t get the $_POST value of the textbox, it gets the value of zero like how the textbox is initialized every time.