-1

I am new in javascript and I have been stumped by this problem.

I have been through a lot of the prior posts and perhaps missed the answer but my question is a bit different, I have a form which I need to validate the user's input entries, most of the entries are numbers in the same range, another is % so it must be between 1 and 100 (the formula divides it by 100 so the user does not put in a decimal.

Actually between 1 and 10 (10% is the max)

My html for one of the inputs is:

<input style="" name="size" id="size" class="inp" value="25000" onblur="sqftvalidate();">

(If I need to post the entire page or table, please let me know)

the function is:

 <script>

 /*   Test function with size  input line 499  */

function sqftvalidate(x)
{
   if(isNaN(x)||x<1000||x>100000)
   {
       alert("Value good ");          // to test if validation is working 

       //docalculation();  this is the function to call if the validation is good 
       return true;
  }
  else
  {
       alert("Value must be between 1,000 and 1,000,000");
       return false;
  }
}
</script>  

<!--   validate input functions  end    -->
1
  • 1
    Try with onblur="sqftvalidate(this.value);". Commented Apr 14, 2015 at 11:59

2 Answers 2

0

Check your condition, it is totally opposite of what you need.

So simply replace code inside if with the code inside else statement.

Sign up to request clarification or add additional context in comments.

Comments

0

I think your logic is also wrong + you should also pass parameter to function - sqftvalidate(this.value)... Otherwise you don't know what value of x is (undefined)...

if(isNaN(x)||x<1000||x>100000)
 {
     alert("Value must be between 1,000 and 1,000,000"); 
  }
  else //or you could write (!isNaN(x) && x>=1000 && x<=100000)
 {
     alert("Ok...");
 }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.