Skip to main content
Participating Frequently
September 19, 2023
Answered

Form fill colour on focus/blur

  • September 19, 2023
  • 2 replies
  • 1771 views

Hi,

I'm a bit stuck with a form I have been given with some Javascript that has both on focus and on blur triggers. The downside to this is that each field needs to have two Javascript tigger set, which gets super time consuming on a large form. 

 

What I would like is it to is fill the yellow on focus and then set back to trasparent in the same bit of code (saving me from having to add the on Blur trigger) or set when it printing the document to be transparent but i'm not sure if that is possible?.

 

below is the code that has been used in these old forms i'm updating.

 

function HiLite()
{
if (app.viewerVersion > 4.05)

{
var MyField = event.target;
var rgEmptyTest = /^\s*$/;
color.ltYellow = new Array("RGB",1,0.994,0.820);

if(event.name == "Focus")
{
if(MyField.type == "button")
{
MyField.borderColor = color.red;
}
else
{
MyField.fillColor = color.ltYellow;
}
}

else if(event.name == "Blur")
{
if(rgEmptyTest.test(event.value))
{
MyField.fillColor = color.transparent;
MyField.borderColor = color.transparent;
}

else
{
MyField.fillColor = color.transparent;
MyField.borderColor = color.transparent;
}
}
}
}

This topic has been closed for replies.
Correct answer try67

oh also relised I need to apply an exclusion to a few other fields that have set colour as well that i don't want changed it it possible just to exclude those 4 field names ("SignField", "Save", "Clear" And "Print") from the loop?


Try this:

 

var fieldsToExclude = ["SignField", "Save", "Clear", "Print"];
for (var i=0; i<this.numFields; i++) {
	var fname = this.getNthFieldName(i);
	if (fieldsToExclude.indexOf(fname)!=-1) continue;
	var f = this.getField(fname);
	f.setAction("OnFocus", "HiLite();");
	f.setAction("OnBlur", "HiLite();");
}

2 replies

Em-AAuthor
Participating Frequently
September 20, 2023

so there is no way to get this to function with just using 'on focus' trigger? the code in the link looks like a simpler version of the code thats being used but till needs both 'on focus' and 'on blur' triggers?

try67
Community Expert
Community Expert
September 21, 2023

No, you have to apply a call to the function under both triggers, but this can also be automated using a script.

Nesa Nurani
Community Expert
Community Expert
September 20, 2023

In field properties, you can set it to be visible but doesn't print.

 

 

Em-AAuthor
Participating Frequently
September 20, 2023

wouldn't that not print text as well if someone has already filled out the form? not really what i'm after

Nesa Nurani
Community Expert
Community Expert
September 21, 2023

You can change display state of a field with a script, for example as Document action 'Will Print' you can check if the fields are empty and change their state to 'doesn't print' (display.noPrint).