Hi,I’ve had a good look round the web; but I can’t find the code to change the colour of the field based on certain values.
e.g. I am using an @Contains formula, to match some stuff, if it matches, I want RED colour for the field ! If not I don’t CARE what colour it is, provided it isn’t RED colour.
I’ve seem previous answers refering to putting some JavaScript into the OnBlur event to acheive this, however I don’t know JavaScript and no code example was provided…
I also found this:-
http://filemakeradvisor.com/doc/13227
But sadly, you have to subsribe (i.e. give money too) to view this particular document…
Any ideas anyone??
Cheers
ab
Subject: Has someone got the Javascript for the On Blur event to change colour/color?
The JS equivalent of @Contains is either indexOf() (for exact string matches) or using a regular expression and test(), depending on the complexity of what you are looking for.
Here’s a simple version of the onblur for a regular ol’ text field:
this.style.color = (this.value.toLowerCase().indexOf(‘badstring’)>-1)?‘red’:‘black’
That will only work properly if your “make it red” value is “badstring” (in any case). Change that to the lowercase version of your bad value.
Oh, and thank-you for spelling “colour” correctly in your subject line.
Subject: RE: Has someone got the Javascript for the On Blur event to change colour/color?
Stan,Thanks. Lets pretend I’m really dumb and don’t know anything about Javascript…
How can I make it evaluate this statement from my formula?
TrimmedList:=
@Trim(Prog);
@If(TrimmedList=“”) |
!@If(@Contains(ComplianceProgs;TrimmedList))
If the relevant program is in the list, the field should be Red - if not Black…
Any ideas? Sorry to post again just can’t figure it out…
Subject: RE: Has someone got the Javascript for the On Blur event to change colour/color?
Okay, you’re really dumb for the purposes of this exercise. The colour change is not a problem – we’ve got that part in the bag. The real problem, then, is the @Contains part with a pair of lists. Formula Language is unusual in the programming world in the way it handles arrays/lists seamlessly. In the rest of the world, you have to do the comparisons yourself. If either of these values (Prog or ComplianceProgs) or both can be guaranteed to be single value, then the code is fairly simple. Web field values aren’t arrays while they sit in the browser, so you just need to use: multivaluefield.value.toLowerCase().indexOf(singlevaluefield.value.toLowerCase()) > -1
as the check in the code I supplied earlier. If both can contain multiple values, then the code gets a bit more complex. A bit much to rattle off over a coffee break, anyway. I’ll be back with more.
Subject: RE: Has someone got the Javascript for the On Blur event to change colour/color?
Stan,Many thanks.
If it helps, I am working only on the Notes Client. Just seen in the help that onBlur doesn’t work there anyway…
My brain hurts.
Thanks for all your help so far…
Subject: RE: Has someone got the Javascript for the On Blur event to change colour/color?
It’s not just that the onblur doesn’t work, but you can’t change the field widget definition on the fly, either – in the Notes client, that counts as a design change, and you just do NOT want to be going there for any reason. Have a weekend instead…
Subject: RE: Has someone got the Javascript for the On Blur event to change colour/color?
OK mate, perhaps that’s why it keeps saying that it has errors compiling the javascript…
Thanks for all your help anyway, going home now!
Subject: Has someone got the Javascript for the On Blur event to change colour/color?
function changecolor(fld){fld.style.color=‘yellow’ //changes text color
fld.style.backgroundColor = ‘red’ //changes background}
you can check the condition and call this function
Subject: RE: Has someone got the Javascript for the On Blur event to change colour/color?
Cool! But how do I check the condition in JavaScript as well???