peddel Posted August 26, 2008 Share Posted August 26, 2008 I got this code for disabling the fields depening on what "ploeg" is selected. When i start the page, nothing is disabled, changing the selection doesnt make it work also. My code for the selection "ploeg" = Ploeg : <select name="ploeg" size="1" onchange="checkploeg();"> <option value="vroeg" selected="selected">Vroege ploeg</option> <option value="laat" onchange="return checkploeg();">Late ploeg</option> <option value="nacht" onchange="return checkploeg();">Nacht ploeg</option> </select> the javascript function that is called is this one = function checkploeg(){ var ploeg = document.forms[0].ploeg.options[document.forms[0].ploeg.selectedIndex].text; if(ploeg == "vroeg"){ document.forms[0].EF1.disabled="false"; document.forms[0].EF2.disabled="false"; document.forms[0].B1A.disabled="true"; document.forms[0].B1B.disabled="true"; document.forms[0].B2A.disabled="true"; document.forms[0].B2B.disabled="true"; document.forms[0].uB1A.disabled="true"; document.forms[0].uB1B.disabled="true"; document.forms[0].uB2A.disabled="true"; document.forms[0].uB2B.disabled="true"; document.forms[0].DeNOx.disabled="false"; document.forms[0].ammoniak.disabled="false"; document.forms[0].H2Oput.disabled="true"; document.forms[0].H2Otank.disabled="true"; document.forms[0].osmoseV.disabled="false"; document.forms[0].cediV.disabled="false"; document.forms[0].vf1V.disabled="false"; document.forms[0].vf2V.disabled="false"; document.forms[0].vf3V.disabled="false"; document.forms[0].vf4V.disabled="false"; document.forms[0].vf8V.disabled="false"; document.forms[0].vf10V.disabled="false"; document.forms[0].vf9V.disabled="false"; document.forms[0].vf11V.disabled="false"; document.forms[0].osmoseL.disabled="true"; document.forms[0].cediL.disabled="true"; document.forms[0].vf1L.disabled="true"; document.forms[0].vf2L.disabled="true"; document.forms[0].vf3L.disabled="true"; document.forms[0].vf4L.disabled="true"; document.forms[0].vf8L.disabled="true"; document.forms[0].vf10L.disabled="true"; document.forms[0].vf9L.disabled="true"; document.forms[0].vf11L.disabled="true"; document.forms[0].osmoseN.disabled="true"; document.forms[0].cediN.disabled="true"; document.forms[0].vf1N.disabled="true"; document.forms[0].vf2N.disabled="true"; document.forms[0].vf3N.disabled="true"; document.forms[0].vf4N.disabled="true"; document.forms[0].vf8N.disabled="true"; document.forms[0].vf10N.disabled="true"; document.forms[0].vf9N.disabled="true"; document.forms[0].vf11N.disabled="true"; document.forms[0].effluent.disabled="true"; document.forms[0].gastellerD.disabled="false"; document.forms[0].gastellerA.disabled="false"; document.forms[0].AWFR1.disabled="true"; document.forms[0].AWFR2.disabled="true"; document.forms[0].uurtellerA.disabled="true"; document.forms[0].uurtellerF.disabled="true"; document.forms[0].volgnummerV.disabled="false"; document.forms[0].volgnummerL.disabled="true"; document.forms[0].volgnummerN.disabled="true"; } if(ploeg == "laat"){ document.forms[0].EF1.disabled="true"; document.forms[0].EF2.disabled="true"; document.forms[0].B1A.disabled="false"; document.forms[0].B1B.disabled="false"; document.forms[0].B2A.disabled="false"; document.forms[0].B2B.disabled="false"; document.forms[0].uB1A.disabled="false"; document.forms[0].uB1B.disabled="false"; document.forms[0].uB2A.disabled="false"; document.forms[0].uB2B.disabled="false"; document.forms[0].DeNOx.disabled="true"; document.forms[0].ammoniak.disabled="true"; document.forms[0].H2Oput.disabled="false"; document.forms[0].H2Otank.disabled="false"; document.forms[0].osmoseV.disabled="true"; document.forms[0].cediV.disabled="true"; document.forms[0].vf1V.disabled="true"; document.forms[0].vf2V.disabled="true"; document.forms[0].vf3V.disabled="true"; document.forms[0].vf4V.disabled="true"; document.forms[0].vf8V.disabled="true"; document.forms[0].vf10V.disabled="true"; document.forms[0].vf9V.disabled="true"; document.forms[0].vf11V.disabled="true"; document.forms[0].osmoseL.disabled="false"; document.forms[0].cediL.disabled="false"; document.forms[0].vf1L.disabled="false"; document.forms[0].vf2L.disabled="false"; document.forms[0].vf3L.disabled="false"; document.forms[0].vf4L.disabled="false"; document.forms[0].vf8L.disabled="false"; document.forms[0].vf10L.disabled="false"; document.forms[0].vf9L.disabled="false"; document.forms[0].vf11L.disabled="false"; document.forms[0].osmoseN.disabled="true"; document.forms[0].cediN.disabled="true"; document.forms[0].vf1N.disabled="true"; document.forms[0].vf2N.disabled="true"; document.forms[0].vf3N.disabled="true"; document.forms[0].vf4N.disabled="true"; document.forms[0].vf8N.disabled="true"; document.forms[0].vf10N.disabled="true"; document.forms[0].vf9N.disabled="true"; document.forms[0].vf11N.disabled="true"; document.forms[0].effluent.disabled="false"; document.forms[0].gastellerD.disabled="true"; document.forms[0].gastellerA.disabled="true"; document.forms[0].AWFR1.disabled="false"; document.forms[0].AWFR2.disabled="false"; document.forms[0].uurtellerA.disabled="true"; document.forms[0].uurtellerF.disabled="true"; document.forms[0].volgnummerV.disabled="true"; document.forms[0].volgnummerL.disabled="false"; document.forms[0].volgnummerN.disabled="true"; } if(ploeg == "nacht"){ document.forms[0].EF1.disabled="true"; document.forms[0].EF2.disabled="true"; document.forms[0].B1A.disabled="true"; document.forms[0].B1B.disabled="true"; document.forms[0].B2A.disabled="true"; document.forms[0].B2B.disabled="true"; document.forms[0].uB1A.disabled="true"; document.forms[0].uB1B.disabled="true"; document.forms[0].uB2A.disabled="true"; document.forms[0].uB2B.disabled="true"; document.forms[0].DeNOx.disabled="true"; document.forms[0].ammoniak.disabled="true"; document.forms[0].H2Oput.disabled="true"; document.forms[0].H2Otank.disabled="true"; document.forms[0].osmoseV.disabled="true"; document.forms[0].cediV.disabled="true"; document.forms[0].vf1V.disabled="true"; document.forms[0].vf2V.disabled="true"; document.forms[0].vf3V.disabled="true"; document.forms[0].vf4V.disabled="true"; document.forms[0].vf8V.disabled="true"; document.forms[0].vf10V.disabled="true"; document.forms[0].vf9V.disabled="true"; document.forms[0].vf11V.disabled="true"; document.forms[0].osmoseL.disabled="true"; document.forms[0].cediL.disabled="true"; document.forms[0].vf1L.disabled="true"; document.forms[0].vf2L.disabled="true"; document.forms[0].vf3L.disabled="true"; document.forms[0].vf4L.disabled="true"; document.forms[0].vf8L.disabled="true"; document.forms[0].vf10L.disabled="true"; document.forms[0].vf9L.disabled="true"; document.forms[0].vf11L.disabled="true"; document.forms[0].osmoseN.disabled="false"; document.forms[0].cediN.disabled="false"; document.forms[0].vf1N.disabled="false"; document.forms[0].vf2N.disabled="false"; document.forms[0].vf3N.disabled="false"; document.forms[0].vf4N.disabled="false"; document.forms[0].vf8N.disabled="false"; document.forms[0].vf10N.disabled="false"; document.forms[0].vf9N.disabled="false"; document.forms[0].vf11N.disabled="false"; document.forms[0].effluent.disabled="true"; document.forms[0].gastellerD.disabled="true"; document.forms[0].gastellerA.disabled="true"; document.forms[0].AWFR1.disabled="true"; document.forms[0].AWFR2.disabled="true"; document.forms[0].uurtellerA.disabled="false"; document.forms[0].uurtellerF.disabled="false"; document.forms[0].volgnummerV.disabled="true"; document.forms[0].volgnummerL.disabled="true"; document.forms[0].volgnummerN.disabled="false"; } return true; } Anyone gots a clue why it is not working? Quote Link to comment Share on other sites More sharing options...
peddel Posted August 26, 2008 Author Share Posted August 26, 2008 bumpzor Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 26, 2008 Share Posted August 26, 2008 The problem is that you are setting the disabled state to the STRING values "true" or "false" not the boolean values of true and false. Incorrect: document.forms[0].EF1.disabled="false"; Correct: document.forms[0].EF1.disabled=false; Also, you can cut down the amount of code needed a great deal with a little more logic. It appears than many "sections" are either being enabled or disabled completely. You could simply create a function to enable/diable those sections and call them accordingly. function disableBlock2(disableBool) { document.forms[0].B1A.disabled =disableBool; document.forms[0].B1B.disabled =disableBool; document.forms[0].B2A.disabled =disableBool; document.forms[0].B2B.disabled =disableBool; document.forms[0].uB1A.disabled=disableBool; document.forms[0].uB1B.disabled=disableBool; document.forms[0].uB2A.disabled=disableBool; document.forms[0].uB2B.disabled=disableBool; } function disableBlock4(disableBool) { document.forms[0].osmoseV.disabled=disableBool; document.forms[0].cediV.disabled =disableBool; document.forms[0].vf1V.disabled =disableBool; document.forms[0].vf2V.disabled =disableBool; document.forms[0].vf3V.disabled =disableBool; document.forms[0].vf4V.disabled =disableBool; document.forms[0].vf8V.disabled =disableBool; document.forms[0].vf10V.disabled =disableBool; document.forms[0].vf9V.disabled =disableBool; document.forms[0].vf11V.disabled =disableBool; } function disableBlock5(disableBool) { document.forms[0].osmoseL.disabled=disableBool; document.forms[0].cediL.disabled =disableBool; document.forms[0].vf1L.disabled =disableBool; document.forms[0].vf2L.disabled =disableBool; document.forms[0].vf3L.disabled =disableBool; document.forms[0].vf4L.disabled =disableBool; document.forms[0].vf8L.disabled =disableBool; document.forms[0].vf10L.disabled =disableBool; document.forms[0].vf9L.disabled =disableBool; document.forms[0].vf11L.disabled =disableBool; } function disableBlock6(disableBool) { document.forms[0].osmoseN.disabled=disableBool; document.forms[0].cediN.disabled =disableBool; document.forms[0].vf1N.disabled =disableBool; document.forms[0].vf2N.disabled =disableBool; document.forms[0].vf3N.disabled =disableBool; document.forms[0].vf4N.disabled =disableBool; document.forms[0].vf8N.disabled =disableBool; document.forms[0].vf10N.disabled =disableBool; document.forms[0].vf9N.disabled =disableBool; document.forms[0].vf11N.disabled =disableBool; } function checkploeg(){ var ploeg = document.forms[0].ploeg.options[document.forms[0].ploeg.selectedIndex].text; if(ploeg == "vroeg"){ document.forms[0].EF1.disabled=false; document.forms[0].EF2.disabled=false; disableBlock2(true); document.forms[0].DeNOx.disabled=false; document.forms[0].ammoniak.disabled=false; document.forms[0].H2Oput.disabled=true; document.forms[0].H2Otank.disabled=true; disableBlock4(false); disableBlock5(true); disableBlock6(true); disableBlock7(true); document.forms[0].effluent.disabled=true; document.forms[0].gastellerD.disabled=false; document.forms[0].gastellerA.disabled=false; document.forms[0].AWFR1.disabled=true; document.forms[0].AWFR2.disabled=true; document.forms[0].uurtellerA.disabled=true; document.forms[0].uurtellerF.disabled=true; document.forms[0].volgnummerV.disabled=false; document.forms[0].volgnummerL.disabled=true; document.forms[0].volgnummerN.disabled=true; } if(ploeg == "laat"){ document.forms[0].EF1.disabled=true; document.forms[0].EF2.disabled=true; disableBlock2(false); document.forms[0].DeNOx.disabled=true; document.forms[0].ammoniak.disabled=true; document.forms[0].H2Oput.disabled=false; document.forms[0].H2Otank.disabled=false; disableBlock4(true); disableBlock5(false); disableBlock6(true); document.forms[0].effluent.disabled=false; document.forms[0].gastellerD.disabled=true; document.forms[0].gastellerA.disabled=true; document.forms[0].AWFR1.disabled=false; document.forms[0].AWFR2.disabled=false; document.forms[0].uurtellerA.disabled=true; document.forms[0].uurtellerF.disabled=true; document.forms[0].volgnummerV.disabled=true; document.forms[0].volgnummerL.disabled=false; document.forms[0].volgnummerN.disabled=true; } if(ploeg == "nacht"){ document.forms[0].EF1.disabled=true; document.forms[0].EF2.disabled=true; disableBlock2(true); document.forms[0].DeNOx.disabled=true; document.forms[0].ammoniak.disabled=true; document.forms[0].H2Oput.disabled=true; document.forms[0].H2Otank.disabled=true; disableBlock4(true); disableBlock5(true); disableBlock6(false); document.forms[0].effluent.disabled=true; document.forms[0].gastellerD.disabled=true; document.forms[0].gastellerA.disabled=true; document.forms[0].AWFR1.disabled=true; document.forms[0].AWFR2.disabled=true; document.forms[0].uurtellerA.disabled=false; document.forms[0].uurtellerF.disabled=false; document.forms[0].volgnummerV.disabled=true; document.forms[0].volgnummerL.disabled=true; document.forms[0].volgnummerN.disabled=false; } return true; } Quote Link to comment Share on other sites More sharing options...
peddel Posted August 27, 2008 Author Share Posted August 27, 2008 Ok i did this, tough it is still not working, when i select the option, the fields wont disable Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted August 27, 2008 Share Posted August 27, 2008 Change: var ploeg = document.forms[0].ploeg.options[document.forms[0].ploeg.selectedIndex].text; To: var ploeg = document.forms[0].ploeg.options[document.forms[0].ploeg.selectedIndex].value; Quote Link to comment Share on other sites More sharing options...
peddel Posted August 27, 2008 Author Share Posted August 27, 2008 Change: var ploeg = document.forms[0].ploeg.options[document.forms[0].ploeg.selectedIndex].text; To: var ploeg = document.forms[0].ploeg.options[document.forms[0].ploeg.selectedIndex].value; That indeed did the trick Thing is I used the text option to put the text in a string for database storage. Both thx for ur help ! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.