js - checkbox count - print

Discussion in 'JavaScript' started by wtfn00b, Jun 28, 2008.

  1. #1
    Hellow, I want to make function with js,
    with who I can count checboxes witch is checked,
    page countaines only checboxes and text.
    Every text entry is with it's ID where is one checkbox belove it.
    I have about 20 checkboxes and
    I want to do thing like this - check 2 or 3 whatever how much checkboxes and send by ID to print.php?=$id page.
    And the text I get from datebase what's why I need ID.

    Got smth like this by it's wrong:

    function checkbox(form)
    {
    var url = "print.php";
    var all = 0;
    var max = form.checkbox.length;
    for (var idx = 0; idx < max; idx++)
    {
    if (eval("document.form[" + idx + "].checked") == true)
    {
    visi += 1;
    }
    }
    alert("checked" + all ");
    }
     
    wtfn00b, Jun 28, 2008 IP
  2. Randombase

    Randombase Peon

    Messages:
    224
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    On sight, I see two mistakes:
    function checkbox(form)
    {
    var url = "print.php";
    var all = 0;
    var max = form.checkbox.length;
    for (var idx = 0; idx < max; idx++)
    {
    if (document.form[idx].checked == true) //why eval?
    {
    visi += 1;
    }
    }
    alert("checked" + all); //removed the " at the end
    }
    
    Code (markup):
     
    Randombase, Jun 28, 2008 IP
  3. wtfn00b

    wtfn00b Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    function checkbox(form)
    {
    var url = "print.php";
    var all = 0;
    var max = form.checkbox.length;
    for (var idx = 0; idx < max; idx++)
    {
    if (document.form[idx].checked == true) //why eval?
    {
    visi += 1;
    }
    }
    alert("checked" + all); //removed the " at the end
    }

    Okey, and how can I send to print.php?=$id ?
     
    wtfn00b, Jun 29, 2008 IP
  4. wtfn00b

    wtfn00b Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thank you.
     
    wtfn00b, Jun 30, 2008 IP