Javascript to check checkboxes?

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

    #1

    Javascript to check checkboxes?

    Hi all. I'm wondering if there's a way to have checkboxes become
    selected without clicking the mouse. Perhaps if you rollover the
    checkboxes, they could toggle checked and unchecked? Or perhaps you
    could click-and-hold and then drag across a series of checkboxes to
    select them?

    Please let me know,
    Sincerely,
    Paul Rubin
    prubin@equilter .com
  • McKirahan

    #2
    Re: Javascript to check checkboxes?

    "Paul Rubin" <prubin@equilte r.com> wrote in message
    news:f9bb33d4.0 312281453.66c0b 9e5@posting.goo gle.com...[color=blue]
    > Hi all. I'm wondering if there's a way to have checkboxes become
    > selected without clicking the mouse. Perhaps if you rollover the
    > checkboxes, they could toggle checked and unchecked? Or perhaps you
    > could click-and-hold and then drag across a series of checkboxes to
    > select them?
    >
    > Please let me know,
    > Sincerely,
    > Paul Rubin
    > prubin@equilter .com[/color]


    Like the following? Watch for word-wrap.

    <html>
    <head>
    <title>checkme. htm</title>
    <script language="javas cript" type="text/javascript">
    <!--
    function mouser() {
    var form = document.forms[0];
    if (form.box1.chec ked) {
    form.box1.check ed = false;
    } else {
    form.box1.check ed = true;
    }
    }
    // -->
    </script>
    </head>
    <body>
    <form>
    <input type="checkbox" name="box1" value="1" onmouseover="mo user()">
    </form>
    </body>
    </html>


    Comment

    • Janwillem Borleffs

      #3
      Re: Javascript to check checkboxes?

      McKirahan wrote:[color=blue]
      >
      > function mouser() {
      > var form = document.forms[0];
      > if (form.box1.chec ked) {
      > form.box1.check ed = false;
      > } else {
      > form.box1.check ed = true;
      > }
      > }[/color]

      Or:

      function mouser() {
      var theBox = document.forms[0].elements['box1'];
      theBox.checked = !theBox.checked ;
      }

      Depending on which syntax you prefer...


      JW



      Comment

      • Paul Rubin

        #4
        Re: Javascript to check checkboxes?

        Thanks for your kind reply. How about if there are a whole bunch of
        checkboxes, with names, p.1, p.2, p.3, etc ???

        I hope this can be incorporated!
        Sincerely,
        Paul Rubin
        prubin@equilter .com

        "McKirahan" <News@McKirahan .com> wrote in message news:<yZJHb.486 016$Dw6.1425226 @attbi_s02>...[color=blue]
        > "Paul Rubin" <prubin@equilte r.com> wrote in message
        > news:f9bb33d4.0 312281453.66c0b 9e5@posting.goo gle.com...[color=green]
        > > Hi all. I'm wondering if there's a way to have checkboxes become
        > > selected without clicking the mouse. Perhaps if you rollover the
        > > checkboxes, they could toggle checked and unchecked? Or perhaps you
        > > could click-and-hold and then drag across a series of checkboxes to
        > > select them?
        > >
        > > Please let me know,
        > > Sincerely,
        > > Paul Rubin
        > > prubin@equilter .com[/color]
        >
        >
        > Like the following? Watch for word-wrap.
        >
        > <html>
        > <head>
        > <title>checkme. htm</title>
        > <script language="javas cript" type="text/javascript">
        > <!--
        > function mouser() {
        > var form = document.forms[0];
        > if (form.box1.chec ked) {
        > form.box1.check ed = false;
        > } else {
        > form.box1.check ed = true;
        > }
        > }
        > // -->
        > </script>
        > </head>
        > <body>
        > <form>
        > <input type="checkbox" name="box1" value="1" onmouseover="mo user()">
        > </form>
        > </body>
        > </html>[/color]

        Comment

        • McKirahan

          #5
          Re: Javascript to check checkboxes?

          "Paul Rubin" <prubin@equilte r.com> wrote in message
          news:f9bb33d4.0 312290901.5c006 ab2@posting.goo gle.com...[color=blue]
          > Thanks for your kind reply. How about if there are a whole bunch of
          > checkboxes, with names, p.1, p.2, p.3, etc ???
          >
          > I hope this can be incorporated!
          > Sincerely,
          > Paul Rubin
          > prubin@equilter .com
          >[/color]

          The following does what you want.
          (I've used JW's elegant approach.)
          Watch for word-wrap.

          <html>
          <head>
          <title>checkers .htm</title>
          </head>
          <body>
          <form>
          <input type="checkbox" name="p.1" value="One"
          onmouseover="th is.checked=!thi s.checked">
          <input type="checkbox" name="p.2" value="Two"
          onmouseover="th is.checked=!thi s.checked">
          <input type="checkbox" name="p.3" value="Three"
          onmouseover="th is.checked=!thi s.checked">
          <input type="checkbox" name="p.4" value="Four"
          onmouseover="th is.checked=!thi s.checked">
          </form>
          </body>
          </html>




          Comment

          • Paul Rubin

            #6
            Re: Javascript to check checkboxes?

            Works like a charm!
            Thank you,
            Sincerely,
            Paul Rubin
            prubin@equilter .com

            "McKirahan" <News@McKirahan .com> wrote in message news:<czZHb.695 70$VB2.136182@a ttbi_s51>...[color=blue]
            > "Paul Rubin" <prubin@equilte r.com> wrote in message
            > news:f9bb33d4.0 312290901.5c006 ab2@posting.goo gle.com...[color=green]
            > > Thanks for your kind reply. How about if there are a whole bunch of
            > > checkboxes, with names, p.1, p.2, p.3, etc ???
            > >
            > > I hope this can be incorporated!
            > > Sincerely,
            > > Paul Rubin
            > > prubin@equilter .com
            > >[/color]
            >
            > The following does what you want.
            > (I've used JW's elegant approach.)
            > Watch for word-wrap.
            >
            > <html>
            > <head>
            > <title>checkers .htm</title>
            > </head>
            > <body>
            > <form>
            > <input type="checkbox" name="p.1" value="One"
            > onmouseover="th is.checked=!thi s.checked">
            > <input type="checkbox" name="p.2" value="Two"
            > onmouseover="th is.checked=!thi s.checked">
            > <input type="checkbox" name="p.3" value="Three"
            > onmouseover="th is.checked=!thi s.checked">
            > <input type="checkbox" name="p.4" value="Four"
            > onmouseover="th is.checked=!thi s.checked">
            > </form>
            > </body>
            > </html>[/color]

            Comment

            Working...