Link to home
Start Free TrialLog in
Avatar of ccpjc
ccpjcFlag for Canada

asked on

Show and Hide fields in CRM

I have a text area that i need to be visible or hidden depending on a Yes or No from a radio button. But i can't seem to get it to work
I have listed the code I have in the onChange event for the text area

Any help would be appreciated.

Thanks
var categorytype;
categorytype = crmForm.new_benowner1.SelectedText;
 
if (categorytype != 'No')
 
 
{
    crmForm.all.new_benowner1_c.style.visibility = 'hidden';
    crmForm.all.new_benowner1_d.style.visibility = 'hidden';
}
else
{
    crmForm.all.new_benowner1_c.style.visibility = 'visible';
    crmForm.all.new_benowner1_d.style.visibility = 'visible';
}

Open in new window

Avatar of WilyGuy
WilyGuy
Flag of United States of America image

What are you doing ONLOAD? (are they hidden ONLOAD)?
Avatar of ccpjc

ASKER

onload they should be hidden
I find the more effective syntax is :

crmForm.all.new_benowner1_c.style.display = 'none';
crmForm.all.new_benowner1_d.style.display = 'none';
}
else
{
crmForm.all.new_benowner1_c.style.display = '';
crmForm.all.new_benowner1_d.style.display = '';
Avatar of ccpjc

ASKER

doesn't seem to work either
I don't know what else i need?

i have tried both methods in the onChange event.. I am using radio buttons that were set with with bit
Are they hidden initially? (the OnLoad event) (you said they should be)
Avatar of ccpjc

ASKER

they're supposed to be but they don't hide
does that code need to be in the onload? the previous admin for crm has scripts on the same page i'm working on but nothing in onload and they still work fine
Well, if they are supposed to be hidden by default when you open (or create), it should be in the onload first.  Then you would UNHIDE them in the OnChange.

Does that make sense?
Avatar of ccpjc

ASKER

Ok, well I'm not the best with Java, I don't really like it that much, is my syntax correct?
i also put the code into the onLoad event for the form and it's throwing me an error message now

There was an error with thie field's customized event.

Field: crmForm

Event: onLoad

Error: 'crmForm.new_benowner1.SelectedText' is a null or not an object
I need to look at the code again, but this time actually test it :)

So the what are you trying to hide?  The Radio Button bit fields or is that what is being used to determine whether to show or hide the fields in question?
sorry re-read the question, got that

Avatar of ccpjc

ASKER

when the user clicks Yes on the radio button, it is supposed to show a field
if the radio button is no, the text field is hidden
OK, so lets take this a chunk at a time.

First the OnChange Event needs to be editted for the Radio Button field (you indicate you have it on the Text Area).

Second, See the Snippet for the code (keep in mind case sensitivity)

Third, for the OnLoad of the form, include:
crmForm.all.new_benowner1.FireOnChange();
Lastly, you should make sure it defaults at the attribute level to "No"

Good Luck

if (crmForm.new_benowner1.DataValue == false)
{
    crmForm.all.new_benowner1_c.style.visibility = "none";
    crmForm.all.new_benowner1_d.style.visibility = "none";
}
else
{
    crmForm.all.new_benowner1_c.style.visibility = "";
    crmForm.all.new_benowner1_d.style.visibility = "";
}

Open in new window

Avatar of ccpjc

ASKER

thanks for the help, but all it does it throw error messages
field isn't hidden, if i hit yes or no on the radio button it shows the error messages as well

same ones listed as above
Shouldn't be the exact same error....

So look in the attribute list and determine if the names are correct (case sensitive, etc.) and make sure the Radio Box has the correct default in its attribute form.  I assume it was Yes/No....
Any luck....

The code snippet is what worked on my test system.  Understand that I changed the attribute names to what you had.  So benowner1 should be the Radio Button attribute (and as I mentioned this OnChange should be on the Radio Button, not the Text field).  Then benowner1_c and _d are the fields you want to show up.
Avatar of ccpjc

ASKER

ok I'll try and sort this out, this is what I have and where
custom attribute 1 (new_benowner1)= Bit, with Yes and No, the default is No
custom attribute 2 (new_benpre1) = Navchar, listed as Text and limited to 4 characters in length

when the Bit = No, the Navchar should be hidden
I actually just noticed something, with the code listed above, if it worked properly it would hide itself, so i changed the bottom area to new_benpre1

on the form
onLoad -> crmForm.all.new_benowner1.FireOnChange();
new_benowner1 ->
if (crmForm.new_benowner1.DataValue == false)
{
    crmForm.all.new_benpre1_c.style.visibility = "none";
    crmForm.all.new_benpre1_d.style.visibility = "none";
}
else
{
    crmForm.all.new_benpre1_c.style.visibility = "";
    crmForm.all.new_benpre1_d.style.visibility = "";
}
what is new_benpre1_c and new_benpre1_d?

If you only have one field, there should just be the new_benpre1.style.visibility, or am I missing something?
And I assume the onLoad-> is not within that script for the OnChange?
Avatar of ccpjc

ASKER

new_benowner1 is the radio button
new_benpre1 is the text box

the onLoad has crmForm.all.new_benowner1.FireOnChange();

while onChange has
if (crmForm.new_benowner1.DataValue == false)
{
    crmForm.all.new_benpre1_c.style.visibility = "none";
    crmForm.all.new_benpre1_d.style.visibility = "none";
}
else
{
    crmForm.all.new_benpre1_c.style.visibility = "";
    crmForm.all.new_benpre1_d.style.visibility = "";
}
TRY

if (crmForm.new_benowner1.DataValue == false)
{
    crmForm.all.new_benpre1.style.visibility = "none";
}
else
{
    crmForm.all.new_benpre1.style.visibility = "";
}
             
Avatar of ccpjc

ASKER

i'm close to giving up
i took screen shots in a last ditch effort
crm.jpg
your problem if the first line of your onchange event.

if(crmForm.new_benowner1.DataValue == false),

you forgot the .all i.e you have crmForm.new_benowner instead of crmForm.all.new_benowner
Avatar of ccpjc

ASKER

if i use the onload line i get an error
when i put in the .all it gets rid of an error message popping up when i hit yes, but if i go back to no the error message pops up
also the field doesn't hide

i don't get this
Can you open the Entity and show the attribute list with those entities?

Sounds like something simple like the attribute name isn't what you have there.
Beneficial Owner is the Radio Button, correct?

Can we see the attribute properties?
Don't give up.
Avatar of bguss01
bguss01

I have skimmed through the posting but if it is working with the onload by changing the field name to crmForm.all.new_benowner and when you change the radio button, it is still erroring, is might be you did not update it on the onchange event.  

Did you also make the change on the onchange event.
ASKER CERTIFIED SOLUTION
Avatar of t-joe
t-joe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial