Skip to main content
New Participant
July 31, 2023
Answered

Formatting code for forms - allowing for mistakes

  • July 31, 2023
  • 2 replies
  • 1115 views

Hi all,

I found a useful code for changing fill and font colors based off a value.
I've got this working; e.g.

else if(event.value == "A"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 0/255, 0/255];}

 

I'm trying to add code allowing for user typos/mistakes.

I added a clear form button, this works.
However, when re-entering the correct value, it doesnt detect the correct  command.
e.g

 

user types A (gets the above)

user deletes the A, types B but the field doesnt detect;

 

else if(event.value == "B"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}

 

I tried adding the below that i found to the start but doesnt work. 

if(event.value == ""){
event.target.textColor = color.black
event.target.fillColor = color.transparent;}

 

The form will be a basic 5 field template, they can fill and print/stick to a file.
Variable A

VariableB

VariableC

VariableD

User Name

 

Full code:

if(event.value == ""){
event.target.textColor = color.black
event.target.fillColor = color.transparent;}
else if(event.value == "A"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 0/255, 0/255];}
else if(event.value == "B"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "C"){
event.target.textColor = color.black
event.target.fillColor = ["RGB", 255/255, 255/255, 0/255];}
else if(event.value == "D"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 185/255, 255/255];}
else if(event.value == "E"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 64/255, 64/255];}
else if(event.value == "F"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "G"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 0/255, 0/255];}
else if(event.value == "H"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 162/255, 255/255, 0/255];}
else if(event.value == "I"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 110/255, 0/255];}
else if(event.value == "J"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 128/255, 0/255, 255/255];}
else if(event.value == "K"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 0/255, 0/255];}
else if(event.value == "L"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "M"){
event.target.textColor = color.black
event.target.fillColor = ["RGB", 255/255, 255/255, 0/255];}
else if(event.value == "N"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 128/255, 0/255, 255/255];}
else if(event.value == "O"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 185/255, 255/255];}
else if(event.value == "P"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 64/255, 64/255];}
else if(event.value == "Q"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "R"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 26/255, 146/255];}
else if(event.value == "S"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 64/255, 0/255, 0/255];}
else if(event.value == "T"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 255/255, 110/255, 0/255];}
else if(event.value == "U"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "V"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "W"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "X"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}
else if(event.value == "Y"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 128/255, 0/255, 255/255];}
else if(event.value == "Z"){
event.target.textColor = color.white
event.target.fillColor = ["RGB", 0/255, 255/255, 0/255];}

 

I've attached the trial form as it stands

Thanks in advance for any help!

This topic has been closed for replies.
Correct answer Bernd Alheit

It works when you open the form in Adobe Acrobat or Acrobat Reader.

2 replies

New Participant
August 22, 2024

Peter, 


This is really awesome. Would be greatful if you can share the final document. I am trying to create an audit form and this could be a life saver. 

Nesa Nurani
Inspiring
August 22, 2024

You can always describe what you need so we can help you.

philthedon
New Participant
September 2, 2024

Hi Nesa, I am a designer trying to figure out a way amend this Java script for an image field so that the fillColor = color.white is a specific RGB value. At the moment I can't get it to work. (I am clueless on code).

This is the code that someone posted somewhere which works for white backgrounds:

 

event.target.fillColor = color.white;

if (event.target.buttonImportIcon()!=0) event.target.fillColor = color.transparent;

 

I want that event.target.fillColour to be a specific colour that is not white, but a specific RGB colour value.

Any help or simple way of doing it?

Bernd Alheit
Bernd AlheitCorrect answer
Brainiac
July 31, 2023

It works when you open the form in Adobe Acrobat or Acrobat Reader.

New Participant
July 31, 2023

I realised I made a mistake, forgot the basics... forgot the capitilisation in the lookup.