check box

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

    check box

    Here is my function

    <script language="javas cript">
    document.form.B 1.disabled = true;

    function changebutton(){
    if (document.form. C1.value = "ON"){
    document.form.B 1.disabled = false;
    return true;
    }
    else {
    document.form.B 1.disabled = true;
    return true;
    }
    }
    </script>

    So far it's doing what I want it to do, when the document loads it disables
    the button, and when the check value is clicked it would enable the button.
    Now here is the problem, when I uncheck the checkbox the button is not
    disabled.

    I am sure I am missing something very easy.


  • Lasse Reichstein Nielsen

    #2
    Re: check box

    "Samir" <Samir@hotmail. com> writes:
    [color=blue]
    > Here is my function
    >
    > <script language="javas cript">[/color]
    ---
    <script type="text/javascript">
    ---
    The "type" attribute is required in all HTML versions that include the
    script tag.
    [color=blue]
    > document.form.B 1.disabled = true;[/color]

    I recommend using:
    ---
    document.forms['form'].elements['B1'].disabled = true;
    ---
    [color=blue]
    > if (document.form. C1.value = "ON"){[/color]

    Should be "==", not "=". Using "=" makes it an assignment, and it always
    evaluates to something true.
    [color=blue]
    > document.form.B 1.disabled = false;
    > return true;
    > }
    > else {
    > document.form.B 1.disabled = true;
    > return true;
    > }
    > }[/color]

    This can be written shorter:
    ---
    function changebutton(){
    var elems = document.forms['form'].elements;
    elems['B1'].disabled = (elems['C1'].value != "ON");
    return true;
    }
    ---
    [color=blue]
    > I am sure I am missing something very easy.[/color]

    Yep. It's a classic (read: we have all done it at some point :)

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Samir

      #3
      Re: check box

      Still doesn't work. The same thing happens.

      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
      news:ekndcgkg.f sf@hotpop.com.. .[color=blue]
      > "Samir" <Samir@hotmail. com> writes:
      >[color=green]
      > > Here is my function
      > >
      > > <script language="javas cript">[/color]
      > ---
      > <script type="text/javascript">
      > ---
      > The "type" attribute is required in all HTML versions that include the
      > script tag.
      >[color=green]
      > > document.form.B 1.disabled = true;[/color]
      >
      > I recommend using:
      > ---
      > document.forms['form'].elements['B1'].disabled = true;
      > ---
      >[color=green]
      > > if (document.form. C1.value = "ON"){[/color]
      >
      > Should be "==", not "=". Using "=" makes it an assignment, and it always
      > evaluates to something true.
      >[color=green]
      > > document.form.B 1.disabled = false;
      > > return true;
      > > }
      > > else {
      > > document.form.B 1.disabled = true;
      > > return true;
      > > }
      > > }[/color]
      >
      > This can be written shorter:
      > ---
      > function changebutton(){
      > var elems = document.forms['form'].elements;
      > elems['B1'].disabled = (elems['C1'].value != "ON");
      > return true;
      > }
      > ---
      >[color=green]
      > > I am sure I am missing something very easy.[/color]
      >
      > Yep. It's a classic (read: we have all done it at some point :)
      >
      > /L
      > --
      > Lasse Reichstein Nielsen - lrn@hotpop.com
      > DHTML Death Colors:[/color]
      <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue]
      > 'Faith without judgement merely degrades the spirit divine.'[/color]


      Comment

      • kaeli

        #4
        Re: check box

        In article <yLyJc.28026$Jk 2.9136@roc.nntp server.com>, Samir@hotmail.c om
        enlightened us with...[color=blue]
        > Here is my function[/color]

        If it works, it works in IE only.
        [color=blue]
        >
        > <script language="javas cript">[/color]

        <script language="javas cript" type="text/javascript">
        [color=blue]
        > document.form.B 1.disabled = true;[/color]
        If you named your form 'form', it's not really recommended. Name it
        something else, like form1, then do the following for cross-browser
        syntax.
        document.forms["form1"].elements["B1"].disabled = true;

        Do the same for the rest of the references you make to it.
        [color=blue]
        >
        > function changebutton(){
        > if (document.form. C1.value = "ON"){[/color]

        double-equals for equality check.
        if (document.forms["form1"].elements["C1"].value == "ON")
        [color=blue]
        >
        > So far it's doing what I want it to do, when the document loads it disables
        > the button, and when the check value is clicked it would enable the button.
        > Now here is the problem, when I uncheck the checkbox the button is not
        > disabled.[/color]

        That equals things is probably why.


        --
        --
        ~kaeli~
        Shotgun wedding: A case of wife or death.



        Comment

        • Samir

          #5
          Re: check box

          Still doesn't work.


          "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
          news:MPG.1b6080 cc8e24ba53989f9 5@nntp.lucent.c om...[color=blue]
          > In article <yLyJc.28026$Jk 2.9136@roc.nntp server.com>, Samir@hotmail.c om
          > enlightened us with...[color=green]
          > > Here is my function[/color]
          >
          > If it works, it works in IE only.
          >[color=green]
          > >
          > > <script language="javas cript">[/color]
          >
          > <script language="javas cript" type="text/javascript">
          >[color=green]
          > > document.form.B 1.disabled = true;[/color]
          > If you named your form 'form', it's not really recommended. Name it
          > something else, like form1, then do the following for cross-browser
          > syntax.
          > document.forms["form1"].elements["B1"].disabled = true;
          >
          > Do the same for the rest of the references you make to it.
          >[color=green]
          > >
          > > function changebutton(){
          > > if (document.form. C1.value = "ON"){[/color]
          >
          > double-equals for equality check.
          > if (document.forms["form1"].elements["C1"].value == "ON")
          >[color=green]
          > >
          > > So far it's doing what I want it to do, when the document loads it[/color][/color]
          disables[color=blue][color=green]
          > > the button, and when the check value is clicked it would enable the[/color][/color]
          button.[color=blue][color=green]
          > > Now here is the problem, when I uncheck the checkbox the button is not
          > > disabled.[/color]
          >
          > That equals things is probably why.
          >
          >
          > --
          > --
          > ~kaeli~
          > Shotgun wedding: A case of wife or death.
          > http://www.ipwebdesign.net/wildAtHeart
          > http://www.ipwebdesign.net/kaelisSpace
          >[/color]


          Comment

          • kaeli

            #6
            Re: check box

            In article <SjzJc.28581$Jk 2.22299@roc.nnt pserver.com>, Samir@hotmail.c om
            enlightened us with...[color=blue]
            > Still doesn't work.[/color]

            Then post testable code.


            --
            --
            ~kaeli~
            If a chicken and a half can lay an egg and a half in a day
            and a half, how long would it take for a monkey with a
            wooden leg to kick the dill seeds out of a pickle?



            Comment

            • kaeli

              #7
              Re: check box

              In article <SjzJc.28581$Jk 2.22299@roc.nnt pserver.com>, Samir@hotmail.c om
              enlightened us with...[color=blue]
              > Still doesn't work.
              >
              >[/color]

              Post the FULL code you're using or URL. My guess is that the value is
              never equal to "ON" or some such, but we can't tell by only looking at
              the function what values you're using in your HTML.

              --
              --
              ~kaeli~
              If a chicken and a half can lay an egg and a half in a day
              and a half, how long would it take for a monkey with a
              wooden leg to kick the dill seeds out of a pickle?



              Comment

              • Mick White

                #8
                Re: check box

                Samir wrote:
                [color=blue]
                > Here is my function
                >
                > <script language="javas cript">
                > document.form.B 1.disabled = true;
                >[/color]

                Here's mine:
                function changebutton(){
                document.form.B 1.disabled=!doc ument.form.C1.c hecked;
                }
                [color=blue]
                >
                > if (document.form. C1.value = "ON"){[/color]

                C1.value always = "ON", its "checked" property changes. That's what you
                need to monitor.
                [color=blue]
                > document.form.B 1.disabled = false;
                > return true;[/color]
                Why are you returning a Boolean?
                [color=blue]
                > }
                > else {[/color]

                This "else" statement never runs[color=blue]
                > document.form.B 1.disabled = true;
                > return true;
                > }
                > }
                > </script>[/color]
                [color=blue]
                >
                > I am sure I am missing something very easy.
                >[/color]


                Mick

                Comment

                • Samir

                  #9
                  Re: check box

                  Never mind this seems to work for checking

                  if (document.forms["form1"].elements["C1"].checked == true)

                  Thanks again

                  "kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
                  news:MPG.1b6088 ed5d984698989f9 7@nntp.lucent.c om...[color=blue]
                  > In article <SjzJc.28581$Jk 2.22299@roc.nnt pserver.com>, Samir@hotmail.c om
                  > enlightened us with...[color=green]
                  > > Still doesn't work.
                  > >
                  > >[/color]
                  >
                  > Post the FULL code you're using or URL. My guess is that the value is
                  > never equal to "ON" or some such, but we can't tell by only looking at
                  > the function what values you're using in your HTML.
                  >
                  > --
                  > --
                  > ~kaeli~
                  > If a chicken and a half can lay an egg and a half in a day
                  > and a half, how long would it take for a monkey with a
                  > wooden leg to kick the dill seeds out of a pickle?
                  > http://www.ipwebdesign.net/wildAtHeart
                  > http://www.ipwebdesign.net/kaelisSpace
                  >[/color]


                  Comment

                  • Lasse Reichstein Nielsen

                    #10
                    Re: check box

                    "Samir" <Samir@hotmail. com> writes:
                    [color=blue]
                    > Never mind this seems to work for checking
                    >
                    > if (document.forms["form1"].elements["C1"].checked == true)[/color]

                    You don't need to compare to true. Just do:
                    if (document.forms["form1"].elements["C1"].checked)
                    It is already a boolean.
                    /L
                    --
                    Lasse Reichstein Nielsen - lrn@hotpop.com
                    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                    'Faith without judgement merely degrades the spirit divine.'

                    Comment

                    • Samir

                      #11
                      Re: check box

                      Okay...thanks, that works just like you said.

                      "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message
                      news:3c3tc780.f sf@hotpop.com.. .[color=blue]
                      > "Samir" <Samir@hotmail. com> writes:
                      >[color=green]
                      > > Never mind this seems to work for checking
                      > >
                      > > if (document.forms["form1"].elements["C1"].checked == true)[/color]
                      >
                      > You don't need to compare to true. Just do:
                      > if (document.forms["form1"].elements["C1"].checked)
                      > It is already a boolean.
                      > /L
                      > --
                      > Lasse Reichstein Nielsen - lrn@hotpop.com
                      > DHTML Death Colors:[/color]
                      <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>[color=blue]
                      > 'Faith without judgement merely degrades the spirit divine.'[/color]


                      Comment

                      • Mick White

                        #12
                        Re: check box

                        Samir wrote:
                        [color=blue]
                        > Never mind this seems to work for checking
                        >
                        > if (document.forms["form1"].elements["C1"].checked == true)
                        >
                        > Thanks again
                        >[/color]
                        Did you not see my response?

                        function changebutton(){
                        document.form.B 1.disabled=!doc ument.form.C1.c hecked;
                        }
                        Mick

                        Comment

                        • Dr John Stockton

                          #13
                          Re: check box

                          JRS: In article <yQBJc.30577$Jk 2.25382@roc.nnt pserver.com>, seen in
                          news:comp.lang. javascript, Samir <Samir@hotmail. com> posted at Thu, 15
                          Jul 2004 13:31:24 :[color=blue]
                          >Never mind this seems to work for checking
                          >
                          >if (document.forms["form1"].elements["C1"].checked == true)
                          >
                          >Thanks again
                          >
                          >"kaeli" <tiny_one@NOSPA M.comcast.net> wrote in message
                          >news:MPG.1b608 8ed5d984698989f 97@nntp.lucent. com...[color=green]
                          >> In article <SjzJc.28581$Jk 2.22299@roc.nnt pserver.com>, Samir@hotmail.c om
                          >> enlightened us with...[color=darkred]
                          >> > Still doesn't work.[/color][/color][/color]

                          Responses should go after trimmed quotes; it encourages the competent to
                          reply.

                          Anyone who willingly codes if ( ... == true ) does not know what
                          they are doing.

                          <URL:http://www.merlyn.demo n.co.uk/js-logic.htm#EQ>.

                          --
                          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                          <URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
                          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                          Comment

                          Working...