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 9 of 9
  1. #1
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question using check boxes in IF...THEN statements

    I have a check box on a form for users to check if they are a certain age.

    I need to be able to verify that they checked it. If they did, then "this function" happens, otherwise, "that function" happens. Can you help me out please? Thanks!!

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    Try The following


    <script language="javascript">
    <!--
    chkbox= new Array()

    function check(){
    for (i = 0; i < document.f2.length; i++) {
    if (document.f2[i].type == "checkbox"){
    chkbox[i]=i
    if(document.f2.elements[chkbox[i]].checked==true){
    alert("checkbox "+document.f2[i].name+" is checked")
    }
    else{
    alert("checkbox "+document.f2[i].name+" is NOT checked")
    }
    }
    }
    }
    // -->
    </script>


    <form name="f2">
    18 <input type="checkbox" name="18">
    21 <input type="checkbox" name="21">
    <input type="button" value="Test" onclick="check()">
    </form>



  • #3
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    That didn't help...but I think I need to just show you the code and what I'm wanting. Should have done that in the first place.

    <form name="FrontPage_Form1">
    <input type="text" name="name1"> <input type="checkbox" name="name1_type" value="child">

    ...


    <input type="text" name="reserved_name1">
    ...

    </form>

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


    The ... means that the input fields would be duplicated in order down to name10, name10_type, and reserved_name10.

    From this, here's how I want it to work. Someone enters their name into the first text field, name1. If they are an adult, they will not click the check box next to it, and the value for name1 will automatically populate the value for reserved_name1. However, if the name they enter is for a child, they will check the checkbox. If this is so, it will still populate the reserved_name1 field with the value of name1, but it will also go to all caps.

    So that let's say someone fills it out and enters 6 adult names and 4 children's names. The 4 children's names will be in all-caps. Does this make any sense? More importantly, can it be done?? I really would appreciate any help. thanks so much in advance!!

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41 8' 52" N -95 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It can be done, but we'd need to see the form in its entirety and have a little clearer explanation of the logic involved, preferably without code.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't know how I'm supposed to show you the form without showing code. But I'll try to explain a little more detail...you asked for it.


    The form is for registration for a banquet. First the user has to tell us who all is going to the banquet. They must also mark whether the person in their party is a child or an adult. The people registering can also make requests on who they want to sit with at their table. Each table sits 10 people. We want the form to work like this...

    When a user enters the names of the people in their party into one or more of 10 open textboxes, of course they want to sit with them, so those names will auto-populate the other textboxes at the bottom of the form where the user can make requests on who to sit with.

    For example...I am Doug, and I'm bringing my wife Brenda and our kids Charlie and Olphilia. So I enter our names, and check the boxes next to Charlie and Olphilia's to indicate they are children. The first 4 textbox fields in the "reserve seating" section at the bottom of the form automatically fills in Doug, Brenda, Charlie, and Olphilia. However, because Charlie and Olphilia are children, their names will appear in all-caps or italic. Then I can enter my friends' names, Greg and Betty, in two of the other 6 open spots in the reserve seating section. Does this make sense??

    I dont know what else I can say to make it any clearer than that. Please ask though if you need more clarification. Thanks

  • #6
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Is there a specific reason you have to do it like that? If so, my answer is useless, but it might be an easier alternative.

    It seems a bit strange that you have to duplicate the values in one set of text fields into another set of text fields. Can you just have a text field and a select box associated with each of these fields to specify whether the field is an adult, child, or friend?


    <html>
    <head>
    <script language="javascript">
    function italicize(gname, gtype){
    if ((gtype.options[gtype.selectedIndex].text)=="Child")
    gname.style.fontStyle='italic';
    else
    gname.style.fontStyle='normal';
    }
    </script>
    </head>
    <body>
    <form name="myform">
    <input type="text" name="guest_name_1">
    <select name="guest_type_1" onchange="italicize(document.myform.guest_name_1, this)">
    <option>Adult</option>
    <option>Child</option>
    <option>Preferred Friend</option>
    </select>
    <br>
    <input type="text" name="guest_name_2">
    <select name="guest_type_2" onchange="italicize(document.myform.guest_name_2, this)">
    <option>Adult</option>
    <option>Child</option>
    <option>Preferred Friend</option>
    </select>
    </form>

    </body>
    </html>
    Last edited by arnyinc; 01-14-2003 at 08:25 PM.

  • #7
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That's a good point. If that would be easier to accomplish what I want, then yeah go ahead and show me how it'd work. It makes more sense to do it that way as well. But now, can you make it so, if the name entered is someone the user wants to sit with, it has maybe a bold style or something like that to distinguish who is registering as an adult, who is a child, and who is just a request-to-be-seated-next-to? Thanks!

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    That can be accomplished by changing that italicize() function. This will italicize children's names, bold Adult names, and leave friend's name plain.

    Code:
    function italicize(gname, gtype){ 
    if ((gtype.options[gtype.selectedIndex].text)=="Child"){
    	gname.style.fontStyle='italic'; 
    	gname.style.fontWeight='normal'; 
    }
    else if ((gtype.options[gtype.selectedIndex].text)=="Adult"){
    	gname.style.fontStyle='normal';
    	gname.style.fontWeight='bold';
    }
    else { //friend
    	gname.style.fontStyle='normal'; 
    	gname.style.fontWeight='normal'; 
    }
    }

  • #9
    New Coder
    Join Date
    Oct 2002
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Instead of making the style change for the child, how about making it so that "(child)" would be entered at the end of the name entered? So, if it's an adult, nothing happens. If it's a child, add (child) at the end of the name, and if it's a friend, change it to all caps. ( using value.toUpperCase(); )

    how about that??


  •  

    Posting Permissions

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