- Jscript to hide fields
- Posted by Mark Braithwaite on April 2nd, 2008
Hi
We have created two custom entities named suppliers and business partners.
We would prefer not to create account records and use the relationship type
field so we created these custom entities.
We now have on the Contact form three seperate fields that a contact could
be related to. These fields are parent customer, parent supplier and parent
business partner. A Contact should only be associated with one parent record.
We would like to write Jscript which hides the remaining fields if one of
the fields is populated. If a user associates a Contact with a parent
customer then the parent business partner and parent supplier fields are
hidden.
We have attempted to write Jscript using the On Load event but we are a bit
unsure as to how we would go about this.
We would really appreciate it if someone could take a look at the Jscript
below and point us in the right direction.
if
crmForm.all.new_parentsupplierid.DataValue != null II
crmForm.all.new_parentbusinesspartnerid.DataValue != null II
crmForm.all.parentcustomerid.DataValue != null
then
crmForm.all.new_parentsupplierid_d.style.visibilit y = ' hidden'
crmForm.all.new_parentbusinesspartnerid_d.style.vi sibility = ' hidden'
crmForm.all.parentcustomerid_d.style.visibility = ' hidden'
crmForm.all.new_parentsupplierid_c.style.visibilit y = ' hidden'
crmForm.all.new_parentbusinesspartnerid_c.style.vi sibility = ' hidden'
crmForm.all.parentcustomerid_c.style.visibility = ' hidden'
Thanks very much
Mark
- Posted by Kamal on April 2nd, 2008
Use the style.display and replace the word field with your field schema
name.
For hiding:
crmForm.all.field.style.display = 'none';
and for showing:
crmForm.all.field.style.display = 'inline';
or
crmForm.all.field.style.display = 'block';
If you are using
--
Kamal Hitari
MBSS, MCNPS, MCTS
2B.net Ltd
http://kamalhitari.blogspot.com
Mark Braithwaite wrote:
- Posted by Fronk on April 3rd, 2008
Mark,
I've used the same calls that you are making and I've gotten the fields,
labels, and icons to disappear. I think the problem with your code is that
you are missing the actual field that you are trying to hide. You have the
_c and _d for the label and the icon but not the actual field.
Here's what I've done to make this work:
var type = crmForm.all.new_contacttype.SelectedText;
switch(type)
{
case "Vendor":
crmForm.all.parentcustomerid.style.visibility = 'hidden';
crmForm.all.parentcustomerid.style.position = 'absolute';
crmForm.all.parentcustomerid_c.style.visibility = 'hidden';
crmForm.all.parentcustomerid_c.style.position = 'absolute';
crmForm.all.parentcustomerid_d.style.visibility = 'hidden';
crmForm.all.parentcustomerid_d.style.position = 'absolute';
crmForm.all.new_vendorid.style.visibility = 'visible';
crmForm.all.new_vendorid.style.position = 'relative';
crmForm.all.new_vendorid_c.style.visibility = 'visible';
crmForm.all.new_vendorid_c.style.position = 'relative';
crmForm.all.new_vendorid_d.style.visibility = 'visible';
crmForm.all.new_vendorid_d.style.position = 'relative';
break;
default:
crmForm.all.new_vendorid.style.visibility = 'hidden';
crmForm.all.new_vendorid.style.position = 'absolute';
crmForm.all.new_vendorid_c.style.visibility = 'hidden';
crmForm.all.new_vendorid_c.style.position = 'absolute';
crmForm.all.new_vendorid_d.style.visibility = 'hidden';
crmForm.all.new_vendorid_d.style.position = 'absolute';
crmForm.all.parentcustomerid.style.visibility = 'visible';
crmForm.all.parentcustomerid.style.position = 'relative';
crmForm.all.parentcustomerid_c.style.visibility = 'visible';
crmForm.all.parentcustomerid_c.style.position = 'relative';
crmForm.all.parentcustomerid_d.style.visibility = 'visible';
crmForm.all.parentcustomerid_d.style.position = 'relative';
break;
}
This will make the page look like it's not missing any fields instead of
hiding them and leaving all this unused space. You could replace _c with
..parentNode and _d with .parentNode.parentNode and that should work as well.
Either way I think this is what you're looking for.
Good luck,
- Posted by Mark Braithwaite on April 7th, 2008
Hi
Thanks for getting back to me. Your script seems quite helpful in organising
the fields on the form however the problem I am having is with the first part
of the script.
If I use the On Save event, the question is, how do I hide the remaining
fields if a certain value is selected in one of the fields? I only want to
hide the fields that are not populated.
I am going test a few things but I think I may need more help than I
originally expected.
I suppose I could use a script which if all fields are null then do nothing
however if one of the fields are populated then hide the fields that are
null. How would you translate this into Jscript?
Thanks again for any help.
Regards
Mark
"Fronk" wrote:
- Posted by Mark Braithwaite on April 7th, 2008
Hi
Thanks for getting back to me. Your script seems quite helpful in organising
the fields on the form however the problem I am having is with the first part
of the script.
If I use the On Save event, the question is, how do I hide the remaining
fields if a certain value is selected in one of the fields? I only want to
hide the fields that are not populated.
I am going test a few things but I think I may need more help than I
originally expected.
I suppose I could use a script which if all fields are null then do nothing
however if one of the fields are populated then hide the fields that are
null. How would you translate this into Jscript?
Thanks again for any help.
Regards
Mark
"Fronk" wrote: