Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Location
    Orlando
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Collect info from checkboxes

    I'm trying to get a client to push a button that will take them to a page with checkboxes. Then they check all the boxes they want and come back to the first page. How do I get the info saved from checkboxes so I can print it later?

    <html>
    <head>
    hello everybody
    <title> hello </title>
    <script>
    function water()
    {x=0;
    WATER=["320.DOC","318.DOC","316.DOC","315.DOC","314.DOC","310.DOC"];
    document.write(WATER[x]);
    x=x+1;
    return x;
    }
    </script>


    </head>
    <body><p>
    <--\\ Buttons
    <INPUT TYPE="BUTTON" NAME="WATER" value="WATER" onClick=water()>
    <input type="button" name="sewer" value="sewer" onClick=alert("sewer")>
    <input type="button" name="underdrain" value="underdrain" onClick=alert("underdrain")>
    <input type="button" name="forcemain" value="forcemain" onClick=alert("forcemain")>
    <input type="button" name="reclaim" value="reclaim" onClick=alert("reclaim")>
    <input type="button" name="lift_station" value="lift_station" onClick=alert("lift_station")>
    <--\\ checkboxes
    <p><input type="checkbox" name="water0" value="yes" checked> Water[0];
    <p><input type="checkbox" name="water1" value="yes" checked> WATER[1];
    <p><input type="checkbox" name="water2" value="yes" checked>
    <p><input type="checkbox" name="water3" value="yes" checked>
    <p><input type="checkbox" name="water4" value="yes" checked>
    <p><input type="checkbox" name="water5" value="yes" checked>
    <p><input type="checkbox" name="water6" value="yes" checked>
    <input type="checkbox" name="water7" value="yes" checked>
    <input type="checkbox" name="water8" value="yes" checked>
    <input type="checkbox" name="water9" value="yes" checked>
    <input type="checkbox" name="water10" value="yes" checked>

    <script>
    document.write("hi");
    </script>
    </body>
    </html>
    Last edited by Drlvi; 10-12-2003 at 03:03 AM.

  • #2
    Regular Coder Vincent Puglia's Avatar
    Join Date
    Jul 2003
    Location
    where the World once stood
    Posts
    367
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Hi,

    since your code is somewhat confusing -- no form tags, no code to show when or how you are returning to the initial page, no idea if this page is a child of the main page or simply a new location, etc, etc.:

    to access the checkboxes, you need to call a function while passing the form object to it

    <input type='button' onclick=doit(this.form)>
    </form>

    function doit(formObj)
    {
    var chksChecked = "";
    for (var i = 0; i < formObj.length; i++)
    if (formObj.elements[i].type == 'checkbox' && formObj.elements[i].checked)
    {
    chksChecked += formObj.elements[i].name + "|";
    }
    }

    how you send it back to the other page depends on how you are returning and how you opened the checkbox page.

    Vinny
    Where the world once stood
    the blades of grass
    cut me still


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •