Solved

Select Box Disable

Posted on 2000-05-12
2
202 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

685 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