Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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

Kool-Aid

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;
 
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.
 
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.
 

Buy us a coffee!

Back
Top Bottom