Checkboxes

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

    #1

    Checkboxes

    Hi,

    I have a variable number of checkboxes in a form. I have developped a simple
    function to calculate a number whith the quantity of checkboxes checked. I
    put de JS function in onChange or in onClick whith the same problem:
    Function don't execute but after checkbox clicked loses his focus and,
    sometimes, if you click in another checkbox inmediatly after a first one,
    don't execute the function at all, and I lose information. Any ideas of what
    can be the problem?

    Thanks for your interest.

    Selrak


  • CryingClinton

    #2
    Re: Checkboxes

    Post ur whole codes out.

    ccton

    --
    www.vicdir.com
    "Selrak" <desenvolupamen t@softhome.net> дÈëÓʼþ
    news:6OhHc.1405 953$A6.5677323@ telenews.teleli ne.es...[color=blue]
    > Hi,
    >
    > I have a variable number of checkboxes in a form. I have developped a[/color]
    simple[color=blue]
    > function to calculate a number whith the quantity of checkboxes checked. I
    > put de JS function in onChange or in onClick whith the same problem:
    > Function don't execute but after checkbox clicked loses his focus and,
    > sometimes, if you click in another checkbox inmediatly after a first one,
    > don't execute the function at all, and I lose information. Any ideas of[/color]
    what[color=blue]
    > can be the problem?
    >
    > Thanks for your interest.
    >
    > Selrak
    >
    >[/color]


    Comment

    • Selrak

      #3
      Re: Checkboxes

      Sorry, I suposed that the code wasn't important for this problem, because,
      the code does the expected, but only sometimes the event executes it. Here
      goes:

      function newImport(docum ent,boolean_can vi,cost)
      {
      var texteImport = docu.getElement sByName("import _texte");
      var cost2;

      if(boolean_canv i)
      cost2= parseFloat(cost );
      else
      cost2= parseFloat(cost ) * (-1);

      texteImport[0].value = (parseFloat(tex teImport[0].value) + cost2);
      }

      I call the function on
      <input type="checkbox" onChange="JavaS cript:
      newImport(docum ent,this.checke d,1.00);" /> //The number 1.00 is an example.
      In my code is a PHP variable.

      Thanks

      Selrak

      "CryingClin ton" <CryingClinton@ hotmail.com> escribió en el mensaje
      news:cclq02$13v 6$1@mail.cn99.c om...[color=blue]
      > Post ur whole codes out.
      >
      > ccton
      >
      > --
      > www.vicdir.com
      > "Selrak" <desenvolupamen t@softhome.net> дÈëÓʼþ
      > news:6OhHc.1405 953$A6.5677323@ telenews.teleli ne.es...[color=green]
      > > Hi,
      > >
      > > I have a variable number of checkboxes in a form. I have developped a[/color]
      > simple[color=green]
      > > function to calculate a number whith the quantity of checkboxes checked.[/color][/color]
      I[color=blue][color=green]
      > > put de JS function in onChange or in onClick whith the same problem:
      > > Function don't execute but after checkbox clicked loses his focus and,
      > > sometimes, if you click in another checkbox inmediatly after a first[/color][/color]
      one,[color=blue][color=green]
      > > don't execute the function at all, and I lose information. Any ideas of[/color]
      > what[color=green]
      > > can be the problem?
      > >
      > > Thanks for your interest.
      > >
      > > Selrak
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • CryingClinton

        #4
        Re: Checkboxes

        I guess the following may help a little:

        -----------------------------------------------------------
        <script>
        function show_click(o)
        {
        document.getEle mentById('t1'). value+="\r\nonc lick fires: "+o.checked ;
        }

        function show_change(o)
        {
        document.getEle mentById('t1'). value+="\r\nonc hange fires: "+o.checked ;
        }
        </script>
        <input type=checkbox onclick='show_c lick(this)'
        onchange='show_ change(this)'>
        <textarea id=t1 rows=20 cols=50></textarea>
        ----------------------------------------------------------

        The test code shows the onchange event never fires at the 'input
        type=checkbox' object.

        ccton

        --
        www.vicdir.com
        "Selrak" <desenvolupamen t@softhome.net> ????
        news:GhyHc.1426 656$A6.5726488@ telenews.teleli ne.es...[color=blue]
        > Sorry, I suposed that the code wasn't important for this problem, because,
        > the code does the expected, but only sometimes the event executes it. Here
        > goes:
        >
        > function newImport(docum ent,boolean_can vi,cost)
        > {
        > var texteImport = docu.getElement sByName("import _texte");
        > var cost2;
        >
        > if(boolean_canv i)
        > cost2= parseFloat(cost );
        > else
        > cost2= parseFloat(cost ) * (-1);
        >
        > texteImport[0].value = (parseFloat(tex teImport[0].value) + cost2);
        > }
        >
        > I call the function on
        > <input type="checkbox" onChange="JavaS cript:
        > newImport(docum ent,this.checke d,1.00);" /> //The number 1.00 is an[/color]
        example.[color=blue]
        > In my code is a PHP variable.
        >
        > Thanks
        >
        > Selrak
        >
        > "CryingClin ton" <CryingClinton@ hotmail.com> escribi?en el mensaje
        > news:cclq02$13v 6$1@mail.cn99.c om...[color=green]
        > > Post ur whole codes out.
        > >
        > > ccton
        > >
        > > --
        > > www.vicdir.com
        > > "Selrak" <desenvolupamen t@softhome.net> ????
        > > news:6OhHc.1405 953$A6.5677323@ telenews.teleli ne.es...[color=darkred]
        > > > Hi,
        > > >
        > > > I have a variable number of checkboxes in a form. I have developped a[/color]
        > > simple[color=darkred]
        > > > function to calculate a number whith the quantity of checkboxes[/color][/color][/color]
        checked.[color=blue]
        > I[color=green][color=darkred]
        > > > put de JS function in onChange or in onClick whith the same problem:
        > > > Function don't execute but after checkbox clicked loses his focus and,
        > > > sometimes, if you click in another checkbox inmediatly after a first[/color][/color]
        > one,[color=green][color=darkred]
        > > > don't execute the function at all, and I lose information. Any ideas[/color][/color][/color]
        of[color=blue][color=green]
        > > what[color=darkred]
        > > > can be the problem?
        > > >
        > > > Thanks for your interest.
        > > >
        > > > Selrak
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Selrak

          #5
          Re: Checkboxes

          Thanks, I see that onClick is the event I'm looking for, however as you can
          note, if you clikc two times too fast, it loses events :(

          "CryingClin ton" <CryingClinton@ hotmail.com> escribió en el mensaje
          news:ccq49h$2t2 7$1@mail.cn99.c om...[color=blue]
          > I guess the following may help a little:
          >
          > -----------------------------------------------------------
          > <script>
          > function show_click(o)
          > {
          > document.getEle mentById('t1'). value+="\r\nonc lick fires: "+o.checked ;
          > }
          >
          > function show_change(o)
          > {
          > document.getEle mentById('t1'). value+="\r\nonc hange fires: "+o.checked ;
          > }
          > </script>
          > <input type=checkbox onclick='show_c lick(this)'
          > onchange='show_ change(this)'>
          > <textarea id=t1 rows=20 cols=50></textarea>
          > ----------------------------------------------------------
          >
          > The test code shows the onchange event never fires at the 'input
          > type=checkbox' object.
          >
          > ccton
          >
          > --
          > www.vicdir.com
          > "Selrak" <desenvolupamen t@softhome.net> ????
          > news:GhyHc.1426 656$A6.5726488@ telenews.teleli ne.es...[color=green]
          > > Sorry, I suposed that the code wasn't important for this problem,[/color][/color]
          because,[color=blue][color=green]
          > > the code does the expected, but only sometimes the event executes it.[/color][/color]
          Here[color=blue][color=green]
          > > goes:
          > >
          > > function newImport(docum ent,boolean_can vi,cost)
          > > {
          > > var texteImport = docu.getElement sByName("import _texte");
          > > var cost2;
          > >
          > > if(boolean_canv i)
          > > cost2= parseFloat(cost );
          > > else
          > > cost2= parseFloat(cost ) * (-1);
          > >
          > > texteImport[0].value = (parseFloat(tex teImport[0].value) + cost2);
          > > }
          > >
          > > I call the function on
          > > <input type="checkbox" onChange="JavaS cript:
          > > newImport(docum ent,this.checke d,1.00);" /> //The number 1.00 is an[/color]
          > example.[color=green]
          > > In my code is a PHP variable.
          > >
          > > Thanks
          > >
          > > Selrak
          > >
          > > "CryingClin ton" <CryingClinton@ hotmail.com> escribi?en el mensaje
          > > news:cclq02$13v 6$1@mail.cn99.c om...[color=darkred]
          > > > Post ur whole codes out.
          > > >
          > > > ccton
          > > >
          > > > --
          > > > www.vicdir.com
          > > > "Selrak" <desenvolupamen t@softhome.net> ????
          > > > news:6OhHc.1405 953$A6.5677323@ telenews.teleli ne.es...
          > > > > Hi,
          > > > >
          > > > > I have a variable number of checkboxes in a form. I have developped[/color][/color][/color]
          a[color=blue][color=green][color=darkred]
          > > > simple
          > > > > function to calculate a number whith the quantity of checkboxes[/color][/color]
          > checked.[color=green]
          > > I[color=darkred]
          > > > > put de JS function in onChange or in onClick whith the same problem:
          > > > > Function don't execute but after checkbox clicked loses his focus[/color][/color][/color]
          and,[color=blue][color=green][color=darkred]
          > > > > sometimes, if you click in another checkbox inmediatly after a first[/color]
          > > one,[color=darkred]
          > > > > don't execute the function at all, and I lose information. Any ideas[/color][/color]
          > of[color=green][color=darkred]
          > > > what
          > > > > can be the problem?
          > > > >
          > > > > Thanks for your interest.
          > > > >
          > > > > Selrak
          > > > >
          > > > >
          > > >
          > > >[/color]
          > >
          > >[/color]
          >
          >[/color]


          Comment

          • CryingClinton

            #6
            Re: Checkboxes

            I dont think so.

            Man handing a mouse can not faster than computer, never! :-)

            even you focus on the selectbox and press ENTER (this will fire onclick
            event as well), the computer still faster than you, nothing will be losed.

            ccton
            --
            www.vicdir.com
            "Selrak" <desenvolupamen t@softhome.net> ????
            news:nXcIc.1458 848$A6.5810690@ telenews.teleli ne.es...[color=blue]
            > Thanks, I see that onClick is the event I'm looking for, however as you[/color]
            can[color=blue]
            > note, if you clikc two times too fast, it loses events :(
            >
            > "CryingClin ton" <CryingClinton@ hotmail.com> escribi?en el mensaje
            > news:ccq49h$2t2 7$1@mail.cn99.c om...[color=green]
            > > I guess the following may help a little:
            > >
            > > -----------------------------------------------------------
            > > <script>
            > > function show_click(o)
            > > {
            > > document.getEle mentById('t1'). value+="\r\nonc lick fires: "+o.checked ;
            > > }
            > >
            > > function show_change(o)
            > > {
            > > document.getEle mentById('t1'). value+="\r\nonc hange fires: "+o.checked ;
            > > }
            > > </script>
            > > <input type=checkbox onclick='show_c lick(this)'
            > > onchange='show_ change(this)'>
            > > <textarea id=t1 rows=20 cols=50></textarea>
            > > ----------------------------------------------------------
            > >
            > > The test code shows the onchange event never fires at the 'input
            > > type=checkbox' object.
            > >
            > > ccton
            > >
            > > --
            > > www.vicdir.com
            > > "Selrak" <desenvolupamen t@softhome.net> ????
            > > news:GhyHc.1426 656$A6.5726488@ telenews.teleli ne.es...[color=darkred]
            > > > Sorry, I suposed that the code wasn't important for this problem,[/color][/color]
            > because,[color=green][color=darkred]
            > > > the code does the expected, but only sometimes the event executes it.[/color][/color]
            > Here[color=green][color=darkred]
            > > > goes:
            > > >
            > > > function newImport(docum ent,boolean_can vi,cost)
            > > > {
            > > > var texteImport = docu.getElement sByName("import _texte");
            > > > var cost2;
            > > >
            > > > if(boolean_canv i)
            > > > cost2= parseFloat(cost );
            > > > else
            > > > cost2= parseFloat(cost ) * (-1);
            > > >
            > > > texteImport[0].value = (parseFloat(tex teImport[0].value) + cost2);
            > > > }
            > > >
            > > > I call the function on
            > > > <input type="checkbox" onChange="JavaS cript:
            > > > newImport(docum ent,this.checke d,1.00);" /> //The number 1.00 is an[/color]
            > > example.[color=darkred]
            > > > In my code is a PHP variable.
            > > >
            > > > Thanks
            > > >
            > > > Selrak
            > > >
            > > > "CryingClin ton" <CryingClinton@ hotmail.com> escribi?en el mensaje
            > > > news:cclq02$13v 6$1@mail.cn99.c om...
            > > > > Post ur whole codes out.
            > > > >
            > > > > ccton
            > > > >
            > > > > --
            > > > > www.vicdir.com
            > > > > "Selrak" <desenvolupamen t@softhome.net> ????
            > > > > news:6OhHc.1405 953$A6.5677323@ telenews.teleli ne.es...
            > > > > > Hi,
            > > > > >
            > > > > > I have a variable number of checkboxes in a form. I have[/color][/color][/color]
            developped[color=blue]
            > a[color=green][color=darkred]
            > > > > simple
            > > > > > function to calculate a number whith the quantity of checkboxes[/color]
            > > checked.[color=darkred]
            > > > I
            > > > > > put de JS function in onChange or in onClick whith the same[/color][/color][/color]
            problem:[color=blue][color=green][color=darkred]
            > > > > > Function don't execute but after checkbox clicked loses his focus[/color][/color]
            > and,[color=green][color=darkred]
            > > > > > sometimes, if you click in another checkbox inmediatly after a[/color][/color][/color]
            first[color=blue][color=green][color=darkred]
            > > > one,
            > > > > > don't execute the function at all, and I lose information. Any[/color][/color][/color]
            ideas[color=blue][color=green]
            > > of[color=darkred]
            > > > > what
            > > > > > can be the problem?
            > > > > >
            > > > > > Thanks for your interest.
            > > > > >
            > > > > > Selrak
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > >
            > > >[/color]
            > >
            > >[/color]
            >
            >[/color]


            Comment

            • rf

              #7
              Re: Checkboxes


              "CryingClin ton" <CryingClinton@ hotmail.com> wrote in message
              news:ccsqpv$miq $1@mail.cn99.co m...
              [color=blue]
              > "Selrak" <desenvolupamen t@softhome.net> ????
              > news:nXcIc.1458 848$A6.5810690@ telenews.teleli ne.es...[color=green]
              > > Thanks, I see that onClick is the event I'm looking for, however as you[/color]
              > can[color=green]
              > > note, if you clikc two times too fast, it loses events :(
              > >[/color][/color]
              [color=blue]
              > I dont think so.
              > Man handing a mouse can not faster than computer, never! :-)[/color]

              I *do* think so, in this instance.

              Two very quick mouse clicks are translated into a doubleclick.

              The sequence of events is:
              onmousedown, onmouseup, onclick, onmouseup, ondblclick

              There is only one onclick event. The second "onclick event" is translated
              into an ondblclick so the second "onclick event" appears to be lost.

              The OP should handle ondblckick events.

              --
              Cheers
              Richard.


              Comment

              • CryingClinton

                #8
                Re: Checkboxes

                I do agree with the ondblclick part.

                The page interface should notice the users what's happenning due to their
                operation so that they can re-click or something to get the right result. I
                mean the page should display the results somewhere, otherwise there always
                have troubles.

                ccton

                --
                www.vicdir.com
                "rf" <rf@.invalid> news:_OmIc.9040 1$sj4.11821@new s-server.bigpond. net.au...[color=blue]
                >
                > "CryingClin ton" <CryingClinton@ hotmail.com> wrote in message
                > news:ccsqpv$miq $1@mail.cn99.co m...
                >[color=green]
                > > "Selrak" <desenvolupamen t@softhome.net> ????
                > > news:nXcIc.1458 848$A6.5810690@ telenews.teleli ne.es...[color=darkred]
                > > > Thanks, I see that onClick is the event I'm looking for, however as[/color][/color][/color]
                you[color=blue][color=green]
                > > can[color=darkred]
                > > > note, if you clikc two times too fast, it loses events :(
                > > >[/color][/color]
                >[color=green]
                > > I dont think so.
                > > Man handing a mouse can not faster than computer, never! :-)[/color]
                >
                > I *do* think so, in this instance.
                >
                > Two very quick mouse clicks are translated into a doubleclick.
                >
                > The sequence of events is:
                > onmousedown, onmouseup, onclick, onmouseup, ondblclick
                >
                > There is only one onclick event. The second "onclick event" is translated
                > into an ondblclick so the second "onclick event" appears to be lost.
                >
                > The OP should handle ondblckick events.
                >
                > --
                > Cheers
                > Richard.
                >
                >[/color]


                Comment

                • Selrak

                  #9
                  Re: Checkboxes

                  Thanks for your answers. I'll try with onDoubleClick event. I'm allways
                  learning :-)

                  Selrak

                  "CryingClin ton" <CryingClinton@ hotmail.com> escribió en el mensaje
                  news:ccu1dq$15v 8$1@mail.cn99.c om...[color=blue]
                  > I do agree with the ondblclick part.
                  >
                  > The page interface should notice the users what's happenning due to their
                  > operation so that they can re-click or something to get the right result.[/color]
                  I[color=blue]
                  > mean the page should display the results somewhere, otherwise there always
                  > have troubles.
                  >
                  > ccton
                  >
                  > --
                  > www.vicdir.com
                  > "rf" <rf@.invalid>[/color]
                  news:_OmIc.9040 1$sj4.11821@new s-server.bigpond. net.au...[color=blue][color=green]
                  > >
                  > > "CryingClin ton" <CryingClinton@ hotmail.com> wrote in message
                  > > news:ccsqpv$miq $1@mail.cn99.co m...
                  > >[color=darkred]
                  > > > "Selrak" <desenvolupamen t@softhome.net> ????
                  > > > news:nXcIc.1458 848$A6.5810690@ telenews.teleli ne.es...
                  > > > > Thanks, I see that onClick is the event I'm looking for, however as[/color][/color]
                  > you[color=green][color=darkred]
                  > > > can
                  > > > > note, if you clikc two times too fast, it loses events :(
                  > > > >[/color]
                  > >[color=darkred]
                  > > > I dont think so.
                  > > > Man handing a mouse can not faster than computer, never! :-)[/color]
                  > >
                  > > I *do* think so, in this instance.
                  > >
                  > > Two very quick mouse clicks are translated into a doubleclick.
                  > >
                  > > The sequence of events is:
                  > > onmousedown, onmouseup, onclick, onmouseup, ondblclick
                  > >
                  > > There is only one onclick event. The second "onclick event" is[/color][/color]
                  translated[color=blue][color=green]
                  > > into an ondblclick so the second "onclick event" appears to be lost.
                  > >
                  > > The OP should handle ondblckick events.
                  > >
                  > > --
                  > > Cheers
                  > > Richard.
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Checkboxes

                    Selrak wrote:[color=blue]
                    > Thanks, I see that onClick is the event I'm looking for, however
                    > as you can note, if you clikc two times too fast, it loses events :([/color]

                    It is because that double-click is handled by a different event handler,
                    called "ondblclick ". You can probably use event-bubbling in those UAs:

                    function form_ondblclick (e)
                    {
                    var t = (e && e.target || event.srcElemen t);
                    (t.click
                    ? t.click(event)
                    : t.onclick
                    ? t.onclick()
                    : void 0);
                    }

                    <form ... ondblclick="for m_ondblclick(ev ent)" ...>

                    Note: This is partly using proprietary behavior. There is no "dblclick"
                    event in the W3C DOM Level 2 Events Specification or a [on]click()
                    method, only an "ondblclick " event handler attribute in the HTML 4.01
                    Specification.
                    [color=blue]
                    > [...][/color]

                    Please do not top-post. <http://www.jibbering.c om/faq/#FAQ2_3>


                    PointedEars

                    Comment

                    Working...