• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript need som help with a code


New Coder
I have a dropdown list in a pdf with a couple of numbers, i want the text to change color depending on what number is choosen (1-5). I have "Space, 1, 2, 3, 4, 5" because i want the list to be blank when nothing is choosen (space).
The code down below gives me the function i want but the sad part is that the list is white when (space) is choosen and if i remove "if (v == 0){ event.target.textColor = color.white;" then i get a 0 instead of a blank box (space)
any suggestions?

var v = Number(this.getField("Dropdown2.1.0").valueAsString) ;
if (v == 0){
event.target.textColor = color.white;
} else if (v < 4){
event.target.textColor = color.black;
} else if (v > 3){
event.target.textColor = color.red;
event.value = v;


King Coder
Didn't you post the same question in august ?

Why are you surprised you get a white color when the chosen value was 'space' ? That's what you programmed in the first line of the if.
Because I'm pretty sure that Number(this.getField("Dropdown2.1.0").valueAsString) returns zero if the field is blank or space.


King Coder
I know zip, zero, nada, about javascript:x3:.
There's always the possibility to go and learn some... at least the basics. Given that you apparently need (or want?) to work with Javascript, it seems like the right thing to do.
But anyway, the problem should be clear, regardless from the language in question.