Javascript issu

Hi

I have to scripts in my app.

The fisrt one, runs just fine.

The second, simply ignores the first "if" hipoteses.

the code is below:

$(document).on('knack-view-render.view_20', function(event, view, data) {

   

    $("#view_20 td.field_2").each(function() {

     

        var textColor = ($(this).find("span").text().trim() == "Não") ? "#ff0000" : "#1c631f"; // #ff0000 is red and the #1c631f is green

     

        $(this).css("color", textColor);

   

    })

 

});

$(document).on('knack-view-render.view_20', function(event, view, data) {

   

    $("#view_20 td.field_4").each(function() {

       

       

       

        if (parseInt($(this).val(), 10) > 50) {

           

           $(this).css('color', 'red');

           alert("deu certo");

                                                   }

           

            else {

           $(this).css('color', 'blue');

           var texto = ("deu errado" );

           alert(texto); } // #ff0000 is red and the #1c631f is green

       

         

   

    });

 

});

The alert is only designed to check the if conditions.

Thanks for any help.

I think that means your parseInt function was passed something that was NotANumber.

So $(this).val() is not a parseable number.  If you're sure it should be - that probably means $(this) isn't pointing at what you think it is.

You could next try a console.log($(this)); and make sure you are looking at the proper element.

Thanks Richard

I tried and got a NaN output in the Console.

I'm assuming by ignoring, you're saying you are either always getting cells that are blue OR red?  If so,

If it were me, I'd put a console.log(parseInt($(this).val(), 10)); above the if call and see if you're getting what you think you should be before doing anything else.

Title correction: Javascript issue

Body correction: I have TWO scripts in my app.