# Javascript issu

**URL:** <https://forums.knack.com/t/javascript-issu/10146>\
**Category:** API & Custom Code\
**Created:** [July 12, 2016, 4:54pm UTC](https://forums.knack.com/t/javascript-issu/10146 "2016-07-12T16:54:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![PauloPires65613](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@PauloPires65613](https://forums.knack.com/u/PauloPires65613)\
**Post date:** [July 12, 2016, 4:54pm UTC](https://forums.knack.com/t/javascript-issu/10146/1 "2016-07-12T16:54:15Z")

</div>

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) {

&nbsp; &nbsp;

&nbsp; &nbsp; $("#view\_20 td.field\_2").each(function() {

&nbsp; &nbsp; &nbsp;

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

&nbsp; &nbsp; &nbsp;

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

&nbsp; &nbsp;

&nbsp; &nbsp; })

&nbsp;

});

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

&nbsp; &nbsp;

&nbsp; &nbsp; $("#view\_20 td.field\_4").each(function() {

&nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; if (parseInt($(this).val(), 10) \> 50) {

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

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

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;alert("deu certo");

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; else {

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

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var texto = ("deu errado" );

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

&nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; &nbsp;

&nbsp; &nbsp; });

&nbsp;

});

The alert is only designed to check the if conditions.

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![RichStigal91358](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@RichStigal91358](https://forums.knack.com/u/RichStigal91358)\
**Post date:** [July 14, 2016, 2:03pm UTC](https://forums.knack.com/t/javascript-issu/10146/2 "2016-07-14T14:03:10Z")

</div>

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

So $(this).val() is not a parseable number. &nbsp;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.

---

<div class="post-metadata">

**Author:** ![PauloPires65613](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@PauloPires65613](https://forums.knack.com/u/PauloPires65613)\
**Post date:** [July 13, 2016, 4:58pm UTC](https://forums.knack.com/t/javascript-issu/10146/3 "2016-07-13T16:58:36Z")

</div>

Thanks Richard

I tried and got a NaN output in the Console.

---

<div class="post-metadata">

**Author:** ![RichStigal91358](https://avatars.discourse-cdn.com/v4/letter/r/ea666f/32.png) [@RichStigal91358](https://forums.knack.com/u/RichStigal91358)\
**Post date:** [July 13, 2016, 1:45pm UTC](https://forums.knack.com/t/javascript-issu/10146/4 "2016-07-13T13:45:25Z")

</div>

I'm assuming by ignoring, you're saying you are either always getting cells that are blue OR red? &nbsp;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.

---

<div class="post-metadata">

**Author:** ![PauloPires65613](https://avatars.discourse-cdn.com/v4/letter/p/7ab992/32.png) [@PauloPires65613](https://forums.knack.com/u/PauloPires65613)\
**Post date:** [July 12, 2016, 4:59pm UTC](https://forums.knack.com/t/javascript-issu/10146/5 "2016-07-12T16:59:23Z")

</div>

Title correction: Javascript issue

Body correction: I have TWO scripts in my app.
