1

i just began a project in html and jquery and i have to compare validate a period.it means that user must enter two years and the second one should be bigger than the second one.i tried this and it doesn't work: this is my html code

<div class="form-group">
  <label class="col-md-4 control-label" for="pe">Période de fréquentation </label>  
  <div class="col-md-2">

  De <input id="pe" name="pe" type="text" placeholder="année" class="form-control input-md">
  à <input id="pe2" name="pe2" type="text" placeholder="année" class="form-control input-md"> 
  </div>
</div><br/><br/><br/><br/><br/><br/><br/>

and this one is my jquery function:

 ` $(document).ready(function() {
$('#pe').click(function() { {
    if ($(this) > $('#pe')){
		alert("veuillez corriger la periode de frequentation");
		return false ;
}
else return true;
}}}`

5
  • 1
    "the second one should be bigger than the second one". Please rephrase. Commented Apr 3, 2015 at 19:55
  • i mean that if you put 2000 in the first form and 1999 in the second,the function should return false.And 1999 in the first and 2000 in the second one returns true Commented Apr 3, 2015 at 20:00
  • you are comparing two selections to each other. not two primitive values. THat is you are comparing the references of two objects. Which is larger hardly ever makes sense in that context Commented Apr 3, 2015 at 20:06
  • @user3430205 I noticed you ticked my answer as correct but then unticked it. Did the solution not work? Commented Apr 3, 2015 at 20:47
  • sorry,i misticked it without knowing and yeah it worked ,thanks a lot Commented Apr 4, 2015 at 4:46

1 Answer 1

1

Assuming you wanted to check if #pe is larger than #pe2

$('#pe').click(function() { {
if ($(this).val() > $('#pe2').val()){
    alert("veuillez corriger la periode de frequentation");
    return false ;
}
else return true;
Sign up to request clarification or add additional context in comments.

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.