form field checking not working

Discussion in 'jQuery' started by Ferenc Cziryek, May 30, 2019.

?

how can I fix the field check on clicking on submit button to run on all fields?

  1. checking stops possibly because of condition

    0 vote(s)
    0.0%
  2. event.preventDefault myght be applied incorrect

    0 vote(s)
    0.0%
  1. #1
    Hi
    my name is frank(ferenc in hungarian), I have quite a big headache, checking form fields with functions click, each, works untill fields are empty, if I just complete filling partially it doesn't work. at the first ok, the checking stops. please help me, thank you, frank
    the faulty code:
    $(".button1").click(function(){
       var emptyfield = true;
      $(".input-check").each(function(){
        
          //$("span").text(inpattr)
           var inputattr = $(this).attr("id");  
          if ( $(this).val()==="") {
           inputmsg(this, inputattr);
            //$(this).next(".fielderror").html(inpattr+" is EMPTY: Please enter data into this input");
          //$(this).next(".fielderror").addClass('warning').removeClass('ok');
            //$("form").submit(function(e){ });
      //alert('submit intercepted');
      //emptyfield = false;  
      $('.button').submit(function(event){});  
           event.preventDefault();
          } else {
           //inputmsg(this);
           $(this).next('span').text(inpattr + " " + " is Ok");
          }
          //alert(inpattr);
          
      });
         // if ( emptyfield === false ) {
        
        
         // }
        
       });
    Code (javascript):

     

    Attached Files:

    Last edited by a moderator: May 30, 2019
    Ferenc Cziryek, May 30, 2019 IP
  2. Karen May Jones

    Karen May Jones Prominent Member

    Messages:
    3,469
    Likes Received:
    290
    Best Answers:
    1
    Trophy Points:
    380
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,806
    Likes Received:
    4,534
    Best Answers:
    123
    Trophy Points:
    665
    #3
    The checking didn't stop when I ran through your attached html page.
     
    sarahk, May 30, 2019 IP
  4. Ferenc Cziryek

    Ferenc Cziryek Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    Hi
    what I experienced is at the first not empty field the each function did not continue the empty check but stopped, leaving the fields as they were, I don't understand, also I have problem using event,preventDefault. please help me, thank you, frank
     
    Ferenc Cziryek, Jun 2, 2019 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Why are you using JavaScript -- much less the bloated train wreck of ineptiude that is jQuery -- to do the HTML 5 "required" attribute and/or server side processing's job?
     
    deathshadow, Jun 26, 2019 IP
  6. Ferenc Cziryek

    Ferenc Cziryek Greenhorn

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #6
    I've learned a bit of jquery and I thought it can be useful for validation. I didn't believe it will be so complicated and confusing. can I get help to find out what was the mistake I made? thank you, frank
     
    Ferenc Cziryek, Jul 1, 2019 IP