Hi guys,
I am doing a validation form (3 inputs: number of apple, orange and banana). for example i type: 'a' as input in the form that required only number (apple), it will prompt me error then i type the next input orange: 2 and it will accept it, however when i type the 3rd input (banana) a number, it will prompt me error. i wonder what i do wrong.
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines
if(document.getElementById("inputs").elements["apple"].value.search(/^\s*\d+\s*$/) == -1) {
document.getElementById("inputs").elements["cost"].value = NaN;
alert("You have entered "+ val + "\n Please enter a number");
}
else{
var vApple = document.getElementById("apple").value;
}
if(document.getElementById("inputs").elements["orange"].value.search(/^\s*\d+\s*$/) == -1) {
document.getElementById("inputs").elements["cost"].value = NaN;
alert("You have entered" + val + "Please enter a number");
}
else {
var vOrange = document.getElementById("orange").value;
}
if(document.getElementById("inputs").elements["banana"].value.search(/^\s*\d+\s*$/) == -1) {
document.getElementById("inputs").elements["cost"].value = NaN;
alert("You have entered "+ val + "Please enter a number");
//return false;
}
else {
var vBanana = document.getElementById("banana").value;
}
Thanks.