We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,439 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

validation not working

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;
      }
      else
      {
           return true;
      }

    }

 </script>

my form is

i m calling above function on form submitting

onsubmit="return validate();

what should i do?
Regards..
Farhad

3
Contributors
2
Replies
12 Hours
Discussion Span
3 Months Ago
Last Updated
14
Views
Farhad.idrees
Junior Poster
102 posts since Dec 2010
Reputation Points: 11
Solved Threads: 0
Skill Endorsements: 0

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?

JorgeM
Industrious Poster
4,156 posts since Dec 2011
Reputation Points: 297
Solved Threads: 564
Skill Endorsements: 119

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

radhakrishna.p
Posting Whiz in Training
272 posts since Nov 2012
Reputation Points: 29
Solved Threads: 60
Skill Endorsements: 11

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0681 seconds using 2.76MB