Solved

Select Box Disable

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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. …
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now