Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Question 2nd validation doesn't appear

    here's my html code
    Code:
                       <div class="row">
                        <label>Resume Title </label>
                        <label class="error" id='titleerror'>this field is required</label>
                        <input type="text" id="resumetitle" name="ResumeTitle" size="60" maxlength="255" />
                       </div>
    
                       <div class="row">
                        <label>Resume Summary Introduction</label>
                        <label class="error" id='introerror'>this field is required</label>
                       <textarea id="resumeintro" name="ResumeSummaryIntroduction" rows="6" cols="50"></textarea>
                       </div>
    
                        <div class="row buttons">
                         <input id='submitcvbutton' type="submit" name="submitcv" value="Submit CV" />
                        </div>
    here's my jquery code

    Code:
    $(function(){
            $('.error').hide();
            var resumetitle = $('input#resumetitle').val();
            var resumeintro = $('textarea#resumeintro').val();
    
            $('#submitcvbutton').click(function(){
                 $('.error').hide();
    
                if(resumetitle == ""){
                  $('label#titleerror').show();
                  $('input#resumetitle').focus();
                  return false;
                }
                if(resumeintro == ""){
                  $('label#introerror').show();
                  $('textarea#resumeintro').focus();
                  return false;
                }
    
         });
    });

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    The second validation error doesn't appear ONLY IF the first one already appears. This is because of the "return false" after the first if. So where is your problem? What is it you really want to do?

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    64
    Thanks
    12
    Thanked 0 Times in 0 Posts
    I want to check all the forms , that's my main motive

  • #4
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    All the forms? You mean all the fields? At once?
    Code:
            $('#submitcvbutton').click(function(){
                 var myReturn = true;
                 $('.error').hide();
    
                if(resumetitle == ""){
                  $('label#titleerror').show();
                  $('input#resumetitle').focus();
                  myReturn = false;
                }
                if(resumeintro == ""){
                  $('label#introerror').show();
                  $('textarea#resumeintro').focus();
                  myReturn = false;
                }
                return myReturn;
         });


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •