Solved

Select Box Disable

Posted on 2000-05-12
2
201 Views
Last Modified: 2008-03-04
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????)
0
Comment
Question by:markdmolder
2 Comments
 
LVL 1

Accepted Solution

by:
julieg earned 50 total points
ID: 2806723
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
 
LVL 3

Expert Comment

by:bark10
ID: 2811131
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question