Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript If value = 10, do something

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #171457
    chrisburton
    Participant

    I am trying to cycle through specific fields to see if the value is equal to 10. If so, do something. I can’t seem to get it working. Any ideas how I’m going wrong?

    $('.paid').each(function() {
    
      if($('.paid').val() == '10') {
        var message = '10';
        alert(message);
      }
    
    });
    

    CodePen.

    #171460
    chrisburton
    Participant

    @TheDoc

    Ha. I did see undefined in the console at one point.

    As of now it only seems to be getting the first value 15 and not cycling through correctly to check 10.

    #171463
    chrisburton
    Participant

    @TheDoc Thanks for the help!

    I solved it using .map() rather than .each().

    $( ".paid" ).map(function() {
    
      console.log($(this).val());
    
      if($(this).val() == 10) {
        //do something
      }
    
    });
    

    I updated that pen in case you want to see it.

    #171482
    chrisburton
    Participant

    Is there a way to convert this to pure Javascript?

    $( ".paid" ).map(function() {
        if($(this).val() == '$0') {
          $(this).parents('tr').addClass('error');
        }
      });
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.