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 10 of 10
  1. #1
    New Coder
    Join Date
    Jan 2003
    Location
    AZ
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting and passing checkbox values??

    I have a name text input and 4 checkboxes and I want to be able to check to see which ones are checked and then have their values and the name value to be transfered to a confirmation type page.

    Here's what I have so far, but still reading on how to write this javaScript stuff. Thanks in advance.


    --------------------

    <html>
    <head>
    <script language="JavaScript">

    function setValue()
    {
    var selected
    for (i=0; i<document.signUp.chkBox.length;i++)
    {
    if (document.signUp.chkBox[i].checked==true)
    selected=i
    }
    }

    </script>
    </head>
    <body>

    <form name="signUp" action="confirm.html" method="post" onSubmit="setValue()">

    <input type="hidden" name="selected" value="(this.selected)">
    <input type="text" size="30" name="userName" value="">
    <input type="checkbox" name="chkBox" value="1">
    <input type="checkbox" name="chkBox" value="2">
    <input type="checkbox" name="chkBox" value="3">
    <input type="checkbox" name="chkBox" value="4">
    </form>

    </body>
    </html>

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would start by using different names for the checkboxs , i only use the same name for things like radio buttons cause one affects the other, this is not so with checkboxes..once you have done that you should be able to work out whether each individual check box has been checked and i think your problem will disappear..
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #3
    New Coder
    Join Date
    Jan 2003
    Location
    AZ
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if I change the names of the checkboxes from "chkBox" to say "1", "2", "3", etc, how do I loop through to check them all?

    thanks

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This code works but you may want to pretty it up

    <form name='boxes'>
    <input name='a1' type='checkbox' checked='true'>
    <input name='a2' type='checkbox'>
    <input name='a3' type='checkbox'>
    <input name='a4' type='checkbox' checked='true'>
    <input name='a5' type='checkbox'>
    <input name='a6' type='checkbox'>
    <input name='a7' type='checkbox'>
    <input name='a8' type='checkbox' checked='true'>
    <input name='a9' type='checkbox'>
    <input name='a10' type='checkbox'>
    </form>
    <script>
    for (i=1; i<=10; i++)
    {if (eval("document.boxes.a"+i+".checked")==true) {alert('yep checkbox #'+i);} else {alert ("nope checkbox #"+i)};}

    </script>

    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #5
    Regular Coder
    Join Date
    Dec 2002
    Location
    Minneapolis, MN
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post
    this line could read

    if (eval("document.boxes.a"+i+".checked")) {alert('yep checkbox #'+i);} else {alert ("nope checkbox #"+i);}

    PS nice name
    anthony

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks
    nice name yourself!
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #7
    New Coder
    Join Date
    Jan 2003
    Location
    AZ
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry, I'm a little slow today after looking at code and books all day.

    I'm trying your suggestion right now.

    Thanks,
    Chris

  • #8
    New Coder
    Join Date
    Jan 2003
    Location
    AZ
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow, I am slow today. Just realized that you guys were talking to each other, "the ez's".

    Maybe I should change my name to "nothingIzEz4me" so I can confuse myself further.

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    197
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thats not completely true
    im ez4ne1
    i just added the 2c as a disguise hehe
    ez
    Animation Rule #64
    Poor quality images are often artistic,
    Poor quality sound is ALWAYS annoying.

  • #10
    New Coder
    Join Date
    Jan 2003
    Location
    AZ
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alright! I have that part working thanks to your help.
    Now if I want to change the value of the checkboxes and send that information to another window, how would I start?

    Do I want to set up the variables before or after I pass them to another page?

    Thanks,
    Chris

    ------Here is my code:-----

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script language="JavaScript">

    function whichChecked(){
    for (i=1; i<=10; i++)
    {if (eval("document.signUp.a"+i+".checked")==true) {alert('yep checkbox #'+i);} else {alert ("nope checkbox #"+i)};}
    }
    </script>

    </head>

    <body>
    <table width="395" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td><form name="signUp" method="post" action="URL_of_confirm_page.html" onSubmit="whichChecked();">
    <table width="395" border="0" cellspacing="3" cellpadding="0">
    <tr>
    <td><table width="395" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="61">Name</td>
    <td width="328"><input type="text" name="name"></td>
    </tr>
    <tr>
    <td>Phone</td>
    <td><input type="text" name="phone"></td>
    </tr>
    <tr>
    <td>Email</td>
    <td><input type="text" name="email"></td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><table width="395" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="26"><input name='a1' type='checkbox'></td>
    <td width="363">Hunting</td>
    </tr>
    <tr>
    <td><input name='a2' type='checkbox'></td>
    <td>Fishing</td>
    </tr>
    <tr>
    <td><input name='a3' type='checkbox'></td>
    <td>OHV</td>
    </tr>
    <tr>
    <td><input name='a4' type='checkbox'></td>
    <td>ALL</td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
    </table>
    </form></td>
    </tr>
    </table>
    </body>
    </html>


  •  

    Posting Permissions

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