Javascript Disable Option

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Quatney

    Javascript Disable Option

    Okay, I'm going nuts here. I know this is VERY easy and I shouldn't
    have problems with this, but I can't seem to figure out what I want to
    do.

    I have a form, with two drop down boxes. I want to be able to disable
    the second drop down box when a specific value is chosen on the first.
    I can't seem to figure out how to do this.

    Go easy on me, I'm a newbie for the most part, but here is my code.

    function getQuestion(){
    var qSelect = document.form1. QuestText.value
    if (document.form1 .QuestText.valu e == "Other"
    {
    document.form1. Select2.disable d = true;
    }
    else
    {
    document.form1. Select2.disable d = false;
    }
    }

    ------- Beginning select statement from the first dropdown box

    <SELECT name="QuestType " id="select1" tabindex="1" style="width:36 0px;"
    required="Y" Description="Qu estion Type"
    onchange="javas cript:getQuesti on()">

    Any clues or suggestions?

  • Michael Winter

    #2
    Re: Javascript Disable Option

    On 21/07/2005 14:48, Quatney wrote:

    [snip]
    [color=blue]
    > function getQuestion(){
    > var qSelect = document.form1. QuestText.value[/color]

    Do you actually use that variable?
    [color=blue]
    > if (document.form1 .QuestText.valu e == "Other"[/color]

    You've omitted a closing parenthesis.

    You can make this simpler:

    function getQuestion(con trol) {
    control.form.el ements.Select2. disabled = ('Other' == this.value);
    }

    <select ... onchange="getQu estion(this);">

    [snip]

    Hope that helps,
    Mike

    --
    Michael Winter
    Prefix subject with [News] before replying by e-mail.

    Comment

    • cosmic foo

      #3
      Re: Javascript Disable Option


      "Quatney" <court.pavillar d@sbcglobal.net > wrote in message
      news:1121953690 .849036.13660@f 14g2000cwb.goog legroups.com...[color=blue]
      > Okay, I'm going nuts here. I know this is VERY easy and I shouldn't
      > have problems with this, but I can't seem to figure out what I want to
      > do.
      >
      > I have a form, with two drop down boxes. I want to be able to disable
      > the second drop down box when a specific value is chosen on the first.
      > I can't seem to figure out how to do this.
      >
      > Go easy on me, I'm a newbie for the most part, but here is my code.
      >
      > function getQuestion(){
      > var qSelect = document.form1. QuestText.value
      > if (document.form1 .QuestText.valu e == "Other"
      > {
      > document.form1. Select2.disable d = true;
      > }
      > else
      > {
      > document.form1. Select2.disable d = false;
      > }
      > }
      >
      > ------- Beginning select statement from the first dropdown box
      >
      > <SELECT name="QuestType " id="select1" tabindex="1" style="width:36 0px;"
      > required="Y" Description="Qu estion Type"
      > onchange="javas cript:getQuesti on()">
      >
      > Any clues or suggestions?
      >[/color]

      <html>
      <head>
      <title>Untitled </title>
      <script language="JavaS cript" type="text/javascript">
      function getQuestion(){
      if (document.form1 .QuestType1.val ue == "2")
      {
      document.form1. QuestType2.disa bled = true;
      }
      else
      {
      document.form1. QuestType2.disa bled = false;
      }
      }
      </SCRIPT>




      </head>

      <body>
      <form action="" name="form1" id="form1">
      <select name="QuestType 1" id="QuestType1 " size="1" style="width:36 0px;"
      tabindex="1" onChange="javas cript:getQuesti on()" required="Y"
      Description="Qu estion Type">
      <option value="1" SELECTED>1</option>
      <option value="2">2</option>
      <option value="3">3</option></select>
      <select name="QuestType 2" id="QuestType2 " size="1" style="width:36 0px;"
      tabindex="2" required="Y" Description="Qu estion Type">
      <option value="1" SELECTED>1</option>
      <option value="2">2</option>
      <option value="3">3</option> </select>
      </form>

      </body>
      </html>


      Comment

      • Quatney

        #4
        Re: Javascript Disable Option

        THANK YOU!

        I don't know what my deal was, but I thought I had tried this. I did
        notice that my "id" and "name" were different on the question types.
        That might have been it, but regardless it's working. Thanks again
        guys.

        Comment

        • Michael Winter

          #5
          Re: Javascript Disable Option

          On 21/07/2005 17:02, Quatney wrote:
          [color=blue]
          > I don't know what my deal was, but I thought I had tried this.[/color]

          Tried what, exactly? Please quote when replying: click 'show options',
          then the 'Reply' link from this section, not the one at the end of the post.
          [color=blue]
          > I did notice that my "id" and "name" were different on the question
          > types. That might have been it, but regardless it's working.[/color]

          If a name and id attribute exist together, then for most elements the
          values must be identical, however the id and name attributes can be
          different on form controls. Consider a group of radio buttons: the
          control name must be the same for them to be linked, but their id
          attribute values must be different because an id can only occur once in
          a document.

          Mike

          --
          Michael Winter
          Prefix subject with [News] before replying by e-mail.

          Comment

          Working...