1,105,331 Community Members

validation not working

Member Avatar
Junior Poster
102 posts since Dec 2010
Reputation Points: 1 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]

Hi i m checking my values from javascript functiions..i m comparing values...
alert is showing that values are not euqal but
but form is still submitting.....when i press submit....

java script code is

<script type="text/javascript">

 function validate(value) 

        var minimum = document.getElementById('min').innerText;
        var maximum = document.getElementById('max').innerText;
        var mini = parseInt(minimum);
        var maxi = parseInt(maximum);

      if( value < mini )

         alert('Value is less than minum value');
         return false;


      else if(value > maxi)
          alert('Value is greater than maximum value');
          return false;
           return true;



my form is

i m calling above function on form submitting

onsubmit="return validate();

what should i do?

Member Avatar
IT Addict
6,413 posts since Dec 2011
Reputation Points: 581 [?]
Q&As Helped to Solve: 963 [?]
Skill Endorsements: 172 [?]

Is it possible that your if..else is always just resulting in the last else block and that's why it's submitting? You can put in some console.log()s to check the values?

Member Avatar
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]

hai Farhad.idrees,

i think you haven't passed any value to validate(some_value) . i dont know exactly whether that 'value' varible may takes default value for comparing .

as JorgeM said , the above reason might be the one .so make that if..else statements properly

one more thing
at line 7 and 8:

var minimum = document.getElementById('min').innerText

there is no innerText propety for an html element in javascript. you may use innerHTML for accessing data from label,div,span elements only

check those once

letme know the status

happy coding

This article has been dead for over three months: Start a new discussion instead
Start New Discussion
Tags Related to this Article