Skip to main content
Participating Frequently
Sep 19, 2023 11:28 PM UTC
Answered

Form fill colour on focus/blur

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 is closed to new replies. Start a new post to keep the conversation going.
try67
try67Correct answer
Community Expert
Sep 26, 2023 8:00 AM UTC

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();");
}

13 replies

Em-AAuthor
Participating Frequently
Sep 20, 2023 11:34 PM UTC

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?

Translate
try67
Community Expert
Community Expert
Sep 21, 2023 9:03 AM UTC

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

Translate
Nesa Nurani
Community Expert
Community Expert
Sep 20, 2023 6:44 AM UTC

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

 

 

Translate
Em-AAuthor
Participating Frequently
Sep 20, 2023 11:29 PM UTC

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

Translate
Nesa Nurani
Community Expert
Community Expert
Sep 21, 2023 5:10 AM UTC

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

Translate