Hiding Fields Using Custom Content and OnChange Script

Hello All,

CRM 7.1i

I am having issues hiding fields and keeping them hidden. I have tried different syntax and the code is not working correctly. In IE, the fields stay hidden after the save but while in the record, the fields dont change depending on the option chosen in oppo_oppotype. In Chrome, the fields change immediately after choosing a oppo_oppotype but after the save, the fields dont stay hidden. I am stumped and getting these two errors in both browsers.

  1. Uncaught TypeError: Cannot read property 'parentNode' of null
  1. Uncaught TypeError: Object [object global] has no method 'attachEvent'

To deal with the method error, I have tried:

1. $(window).load(function ())

2. window.attachEvent ('onload', function ()

CUSTOM CONTENT

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<script>
window.attachEvent ('onload', function () {

ShowOrHide ('oppo_currentproduct', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_budget', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_decisiontimeframe', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_revenueproduct', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_revenueservice', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_forecastsoftware', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_demodate_start', 'oppo_oppotype', 'Service');
ShowOrHide ('oppo_demodate_end', 'oppo_oppotype', 'Service');

ShowOrHide ('oppo_forecastservice', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_forecastservice2', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_retainer', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_tentativeprojstart', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_additionalcontact', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_consultant1', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_zdev_desiredservice', 'oppo_oppotype', 'Software');
ShowOrHide ('oppo_tsentry', 'oppo_oppotype', 'Software');
});
function ShowOrHide (a, b, c)
{
var hideElem=document.getElementById("_Data"+a);
var tElem=document.getElementById("_Data"+b);

if (tElem.childNodes[0].value!=undefined)
{
tElem.childNodes[0].onchange=Function("ShowOrHide('"+a+"','"+b+"','"+c+"')");
if (tElem.childNodes[0].value==c) hideElem.parentNode.style.display="none";
else hideElem.parentNode.style.display="";
}
else if ((tElem.innerText.replace(/ +$/,'')==c)) hideElem.parentNode.style.display="none";
}
</script>

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

ONCHANGE - the reason why I made all the fields visible in the beginning is my attempt to fix the null error.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

var fs = document.getElementById('_Captoppo_forecastsoftware');
var fsd = document.getElementById('_Dataoppo_forecastsoftware');
var sf = document.getElementById('_Captoppo_retainer');
var sfd = document.getElementById('_Dataoppo_retainer');
var rf = document.getElementById('_Captoppo_forecastservice');
var rfd = document.getElementById('_Dataoppo_forecastservice');
var df = document.getElementById('_Captoppo_forecastservice2');
var dfd = document.getElementById('_Dataoppo_forecastservice2');
var ts = document.getElementById('_Captoppo_additionalcontact');
var tsd = document.getElementById('_Dataoppo_additionalcontact');
var td = document.getElementById('_Captoppo_consultant1');
var tdd = document.getElementById('_Dataoppo_consultant1');
var os = document.getElementById('_Captoppo_tentativeprojstart');
var osd = document.getElementById('_Dataoppo_tentativeprojstart');
var ao = document.getElementById('_IDoppo_tsentry');

var br = document.getElementById('_Captoppo_currentproduct');
var brr = document.getElementById('_Dataoppo_currentproduct');
var yt = document.getElementById('_Captoppo_budget');
var yrt = document.getElementById('_Dataoppo_budget');
var mn = document.getElementById('_Captoppo_decisiontimeframe');
var mnm = document.getElementById('_Dataoppo_decisiontimeframe');
var pd = document.getElementById('_Captoppo_revenueproduct');
var pdd = document.getElementById('_Dataoppo_revenueproduct');
var pe = document.getElementById('_Captoppo_revenueservice');
var pee = document.getElementById('_Dataoppo_revenueservice');
var pf = document.getElementById('_Captoppo_demodate_start');
var pff = document.getElementById('_Dataoppo_demodate_start');
var pg = document.getElementById('_Captoppo_demodate_end');
var pgg = document.getElementById('_Dataoppo_demodate_end');
var ph = document.getElementById('_Captoppo_zdev_desiredservice');
var phh = document.getElementById('_Dataoppo_zdev_desiredservice');
fs.style.visibility='visible';
fsd.style.visibility='visible';
oppo_forecastsoftware.style.visibility = 'visible';

br.style.visibility='visible';
brr.style.visibility='visible';
oppo_currentproduct.style.visibility = 'visible';

yt.style.visibility='visible';
yrt.style.visibility='visible';
oppo_budget.style.visibility = 'visible';

mn.style.visibility='visible';
mnm.style.visibility='visible';
oppo_decisiontimeframe.style.visibility = 'visible';

pd.style.visibility='visible';
pdd.style.visibility='visible';
oppo_revenueproduct.style.visibility = 'visible';

pe.style.visibility='visible';
pee.style.visibility='visible';
oppo_revenueservice.style.visibility = 'visible';

pf.style.visibility='visible';
pff.style.visibility='visible';
oppo_demodate_start.style.visibility = 'visible';

pg.style.visibility='visible';
pgg.style.visibility='visible';
oppo_demodate_end.style.visibility = 'visible';

sf.style.visibility = 'visible';
sfd.style.visibility = 'visible';
oppo_retainer.style.visibility = 'visible';

rf.style.visibility = 'visible';
rfd.style.visibility = 'visible';
oppo_forecastservice.style.visibility = 'visible';

df.style.visibility = 'visible';
dfd.style.visibility = 'visible';
oppo_forecastservice2.style.visibility = 'visible';

ts.style.visibility = 'visible';
tsd.style.visibility = 'visible';
oppo_additionalcontact.style.visibility = 'visible';

td.style.visibility = 'visible';
tdd.style.visibility = 'visible';
oppo_consultant1.style.visibility = 'visible';

os.style.visibility = 'visible';
osd.style.visibility = 'visible';
oppo_tentativeprojstart.style.visibility = 'visible';

ao.style.visibility = 'visible';

oppo_tsentry.style.visibility = 'visible';

ph.style.visibility = 'visible';
phh.style.visibility = 'visible';
oppo_zdev_desiredservice.style.visibility = 'visible';

if (this.value == 'Software') {
rf.style.visibility = 'hidden';

rfd.style.visibility = 'hidden';
oppo_forecastservice.style.visibility = 'hidden';

df.style.visibility = 'hidden';
dfd.style.visibility = 'hidden';
oppo_forecastservice2.style.visibility = 'hidden';

sf.style.visibility = 'hidden';
sfd.style.visibility = 'hidden';
oppo_retainer.style.visibility = 'hidden';

ts.style.visibility = 'hidden';
tsd.style.visibility = 'hidden';
oppo_additionalcontact.style.visibility = 'hidden';

td.style.visibility = 'hidden';
tdd.style.visibility = 'hidden';
oppo_consultant1.style.visibility = 'hidden';

os.style.visibility = 'hidden';
osd.style.visibility = 'hidden';
oppo_tentativeprojstart.style.visibility = 'hidden';

ao.style.visibility = 'hidden';

oppo_tsentry.style.visibility = 'hidden';

fs.style.visibility='visible';
fsd.style.visibility='visible';
oppo_forecastsoftware.style.visibility = 'visible';

br.style.visibility='visible';
brr.style.visibility='visible';
oppo_currentproduct.style.visibility = 'visible';

yt.style.visibility='visible';
yrt.style.visibility='visible';
oppo_budget.style.visibility = 'visible';

mn.style.visibility='visible';
mnm.style.visibility='visible';
oppo_decisiontimeframe.style.visibility = 'visible';

pd.style.visibility='visible';
pdd.style.visibility='visible';
oppo_revenueproduct.style.visibility = 'visible';

pe.style.visibility='visible';
pee.style.visibility='visible';
oppo_revenueservice.style.visibility = 'visible';

pf.style.visibility='visible';
pff.style.visibility='visible';
oppo_demodate_start.style.visibility = 'visible';

pg.style.visibility='visible';
pgg.style.visibility='visible';
oppo_demodate_end.style.visibility = 'visible';

ph.style.visibility = 'hidden';
phh.style.visibility = 'hidden';
oppo_zdev_desiredservice.style.visibility = 'hidden';
}

else if(this.value == 'Service' ) {
fs.style.visibility = 'hidden';

fsd.style.visibility = 'hidden';
oppo_forecastsoftware.style.visibility = 'hidden';

sf.style.visibility = 'visible';
sfd.style.visibility = 'visible';
oppo_retainer.style.visibility = 'visible';

rf.style.visibility = 'visible';
rfd.style.visibility = 'visible';
oppo_forecastservice.style.visibility = 'visible';

df.style.visibility = 'visible';
dfd.style.visibility = 'visible';
oppo_forecastservice2.style.visibility = 'visible';

ts.style.visibility = 'visible';
tsd.style.visibility = 'visible';
oppo_additionalcontact.style.visibility = 'visible';

td.style.visibility = 'visible';
tdd.style.visibility = 'visible';
oppo_consultant1.style.visibility = 'visible';

os.style.visibility = 'visible';
osd.style.visibility = 'visible';
oppo_tentativeprojstart.style.visibility = 'visible';

ao.style.visibility = 'visible';

oppo_tsentry.style.visibility = 'visible';

br.style.visibility = 'hidden';
brr.style.visibility = 'hidden';
oppo_currentproduct.style.visibility = 'hidden';

yt.style.visibility = 'hidden';
yrt.style.visibility = 'hidden';
oppo_budget.style.visibility = 'hidden';

mn.style.visibility = 'hidden';
mnm.style.visibility = 'hidden';
oppo_decisiontimeframe.style.visibility = 'hidden';

pd.style.visibility = 'hidden';
pdd.style.visibility = 'hidden';
oppo_revenueproduct.style.visibility = 'hidden';

pe.style.visibility = 'hidden';
pee.style.visibility = 'hidden';
oppo_revenueservice.style.visibility = 'hidden';

pf.style.visibility = 'hidden';
pff.style.visibility = 'hidden';
oppo_demodate_start.style.visibility = 'hidden';

pg.style.visibility = 'hidden';
pgg.style.visibility = 'hidden';
oppo_demodate_end.style.visibility = 'hidden';

ph.style.visibility = 'visible';
phh.style.visibility = 'visible';
oppo_zdev_desiredservice.style.visibility = 'visible';
}

else{
fs.style.visibility='visible';

fsd.style.visibility='visible';
oppo_forecastsoftware.style.visibility = 'visible';

br.style.visibility='visible';
brr.style.visibility='visible';
oppo_currentproduct.style.visibility = 'visible';

yt.style.visibility='visible';
yrt.style.visibility='visible';
oppo_budget.style.visibility = 'visible';

mn.style.visibility='visible';
mnm.style.visibility='visible';
oppo_decisiontimeframe.style.visibility = 'visible';

pd.style.visibility='visible';
pdd.style.visibility='visible';
oppo_revenueproduct.style.visibility = 'visible';

pe.style.visibility='visible';
pee.style.visibility='visible';
oppo_revenueservice.style.visibility = 'visible';

pf.style.visibility='visible';
pff.style.visibility='visible';
oppo_demodate_start.style.visibility = 'visible';

pg.style.visibility='visible';
pgg.style.visibility='visible';
oppo_demodate_end.style.visibility = 'visible';

sf.style.visibility = 'visible';
sfd.style.visibility = 'visible';
oppo_retainer.style.visibility = 'visible';

rf.style.visibility = 'visible';
rfd.style.visibility = 'visible';
oppo_forecastservice.style.visibility = 'visible';

df.style.visibility = 'visible';
dfd.style.visibility = 'visible';
oppo_forecastservice2.style.visibility = 'visible';

ts.style.visibility = 'visible';
tsd.style.visibility = 'visible';
oppo_additionalcontact.style.visibility = 'visible';

td.style.visibility = 'visible';
tdd.style.visibility = 'visible';
oppo_consultant1.style.visibility = 'visible';

os.style.visibility = 'visible';
osd.style.visibility = 'visible';
oppo_tentativeprojstart.style.visibility = 'visible';

ao.style.visibility = 'visible';

oppo_tsentry.style.visibility = 'visible';

ph.style.visibility = 'visible';
phh.style.visibility = 'visible';
oppo_zdev_desiredservice.style.visibility = 'visible';
}

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------