CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript frameworks (http://www.codingforums.com/forumdisplay.php?f=62)
-   -   jQuery 2nd validation doesn't appear (http://www.codingforums.com/showthread.php?t=232847)

capt_nemo777 07-24-2011 10:23 AM

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;
            }

    });
});


devnull69 07-24-2011 12:43 PM

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?

capt_nemo777 07-24-2011 02:10 PM

I want to check all the forms , that's my main motive

devnull69 07-24-2011 02:23 PM

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;
    });



All times are GMT +1. The time now is 01:29 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.