Select Box Disable

Is there a way to disable one select box using another to do so?  heres the scenerio:  we have a credit card list like visa,mastercard, etc.. in the list we also have COD... if this is selected i want to disable the month and year select boxes we have.... i got the script so it doesn't error but it doesn't work!!!!! here it is...





function CheckPay()
{
      var checker,checke
      var choice = document.PostIt.cboPayType.toString();
      checker = "Cash";
      checke = "Call";
      if ((choice.indexOf(checker) < 0) || (choice.indexOf(checke) < 0)) {
            document.PostIt.cboMonth.disabled = true;
            document.PostIt.cboYear.disabled = true;
      }
      else {
            document.PostIt.cboMonth.disabled = false;
            document.PostIt.cboYear.disabled = false;
      }
}



i run this function onBlur of the credit select box (and yes the names of the select boxes begin with cbo????)
markdmolderAsked:
Who is Participating?
 
juliegConnect With a Mentor Commented:
I used a disabling procedure by entering a number in a text box and if say the number was 4, 4 drop down boxes would be disabled, 5, 5 disabled etc.  I used a set disable and setright functions I created myself then onchange command and onsubmit command in Javascript.  The text box looked like this:

Number of Weeks Eligible (must use drop down boxes below to indicate week of vacation):
<td width="368">
<input type="text" Name="NoWeeks" onchange="setdisable()"></td></tr>
</table>

And then all the necessary code was before it:

<script language="javascript">

function setright(){
if (document.vacpost.submit){
document.vacpost.DateA.disabled=false;
document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=false;
      document.vacpost.DateD.disabled=false;
        document.vacpost.DateE.disabled=false;
          document.vacpost.DateF.disabled=false;
            document.vacpost.DateG.disabled=false;
                  }
                  }

function setdisable(){
if (document.vacpost.NoWeeks.value=="1"){
  document.vacpost.DateB.disabled=true;
    document.vacpost.DateC.disabled=true;
      document.vacpost.DateD.disabled=true;
        document.vacpost.DateE.disabled=true;
          document.vacpost.DateF.disabled=true;
            document.vacpost.DateG.disabled=true;
  }
  if (document.vacpost.NoWeeks.value=="2"){
    document.vacpost.DateA.disabled=false;
      document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=true;
      document.vacpost.DateD.disabled=true;
        document.vacpost.DateE.disabled=true;
          document.vacpost.DateF.disabled=true;
            document.vacpost.DateG.disabled=true;
  }
    if (document.vacpost.NoWeeks.value=="3"){
        document.vacpost.DateA.disabled=false;
      document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=false;
      document.vacpost.DateD.disabled=true;
        document.vacpost.DateE.disabled=true;
          document.vacpost.DateF.disabled=true;
            document.vacpost.DateG.disabled=true;
  }
    if (document.vacpost.NoWeeks.value=="4"){
            document.vacpost.DateA.disabled=false;
      document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=false;
          document.vacpost.DateD.disabled=false;

        document.vacpost.DateE.disabled=true;
          document.vacpost.DateF.disabled=true;
            document.vacpost.DateG.disabled=true;
  }
    if (document.vacpost.NoWeeks.value=="5"){
                document.vacpost.DateA.disabled=false;
      document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=false;
          document.vacpost.DateD.disabled=false;

        document.vacpost.DateE.disabled=false;

          document.vacpost.DateF.disabled=true;
            document.vacpost.DateG.disabled=true;
  }
    if (document.vacpost.NoWeeks.value=="6"){
                    document.vacpost.DateA.disabled=false;
      document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=false;
          document.vacpost.DateD.disabled=false;

        document.vacpost.DateE.disabled=false;

          document.vacpost.DateF.disabled=false;

            document.vacpost.DateG.disabled=true;
  }
 
      if (document.vacpost.NoWeeks.value=="7"){
                    document.vacpost.DateA.disabled=false;
      document.vacpost.DateB.disabled=false;
    document.vacpost.DateC.disabled=false;
          document.vacpost.DateD.disabled=false;

        document.vacpost.DateE.disabled=false;

          document.vacpost.DateF.disabled=false;

            document.vacpost.DateG.disabled=false;
  }

  }
 


</script>
0
 
bark10Commented:
Why not use something as simple as this:

<script language="JavaScript">
function CheckPay()
{
      if (PostIt.cboPayType.selectedIndex==2)
            {
            PostIt.cboMonth.disabled = true;
            PostIt.cboYear.disabled = true;
            }
      else
            {
            PostIt.cboMonth.disabled = false;
            PostIt.cboYear.disabled = false;
            }
}

</script>


Just change the selectedIndex value (##) in the script to the value of the index for your COD option.

Also, a better call would be with the onChange() event when compared to the onBlur(), as this does not require the user to click else where for the script to run.  As soon as he selects an option, it runs.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.