Ask a Question related to ASP, Design and Development.

  1. #1

    Default Re: checkboxes

    "cbool" might help
    if cbool(request.form("mychk")) = true then



    "Paul" <paul@themedialounge.com> wrote in message
    news:OExAuoRTDHA.2228@tk2msftngp13.phx.gbl...
    > I know this is gonna sound silly but when I submit a form with a checkbox
    > html control "mychk", how can I see if that is checked or not ?
    >
    > I have tried :
    >
    > if request.form("mychk") = true then
    > ' code
    > else
    > ' code
    > end if
    >
    > But it always executes the code in the else statement meaning it is never
    > true despite the fact I have given the checkbox a value of true.
    >
    >
    >

    only_me Guest

  2. Similar Questions and Discussions

    1. What to do about checkboxes?
      I have a grid with odds and ends of data, some of the fields are true/false checkboxes. The users don't like the fact that the checkboxes are...
    2. PHP checkboxes
      How do I send CHECKBOXES via email through the mail() function in PHP? Example: You have 67 checkboxes, all with unique names, but only want to...
    3. [PHP] Checkboxes
      You could try this: <input type="hidden" name="box1" value="0"> <input type="checkbox" name="box1" value="1"> So basically when it get...
    4. ASP.NET Checkboxes
      Thanx M, and I mean that, but I really need this to work without a postback and frankly it should behave like the other controls are behaving...
    5. CGI and checkboxes
      How do I get the value from a checkbox made with cgi.checkbox ? I need to make a decision based on whether or not the checkbox is checked - will...
  3. #2

    Default Re: checkboxes

    Paul wrote:
    > I know this is gonna sound silly but when I submit a form with a
    > checkbox html control "mychk", how can I see if that is checked or
    > not ?
    >
    > I have tried :
    >
    > if request.form("mychk") = true then
    The variable contains a string, not a boolean value. true is a constant that
    evaluates to either True or False (numerically -1 or 0).

    So you need to a) cast the variable to a boolean using cbool() or b) compare
    the variable to a string, using "true".

    However, this is not the optimal method. If the checkbox is not checked, it
    will have no value. So simply check the variable's length:
    if len(request.form("mychk")) > 0 then
    'it was checked

    HTH,
    Bob Barrows


    Bob Barrows Guest

  4. #3

    Default Re: checkboxes

    If the checkbox is checked then it has a value, if it's not then there's
    nothing
    if Request.Form("mychk")="" then
    'not checked
    else
    'checked
    end if

    or you can specify
    <input type=checkbox name=mychk value='BOB'>

    if Request.Form("mychk")="BOB" then
    'it was checked
    end if

    You can also use the same name for multiple checkboxes (like you do for
    radio buttons)
    <input type=checkbox name=mychk value='BOB'>BOB
    <input type=checkbox name=mychk value='FRED'>FRED

    Response.write Request.Form("mychk") would display BOB, FRED (assuming both
    checked)

    "Paul" <paul@themedialounge.com> wrote in message
    news:OExAuoRTDHA.2228@tk2msftngp13.phx.gbl...
    > I know this is gonna sound silly but when I submit a form with a checkbox
    > html control "mychk", how can I see if that is checked or not ?
    >
    > I have tried :
    >
    > if request.form("mychk") = true then
    > ' code
    > else
    > ' code
    > end if
    >
    > But it always executes the code in the else statement meaning it is never
    > true despite the fact I have given the checkbox a value of true.
    >
    >
    >

    Tom B Guest

  5. #4

    Default Checkboxes

    Hi all,

    I am wondering what would be the best way to handle checkboxes. I am
    making a site that will display several items in a 20-items-per-page
    format and each item will have a checkbox next to it for the user to
    select them. Now, what I need to do is to record the items selected by
    the user when clicking the “Next button” into a MySQL table. Should I
    name all the checkboxes the same, using the item IDs as values and then
    use an array to see which ones where selected or maybe another thing?

    Thanks in advanced,

    Cesar Aracena
    <http://www.icaam.com.ar> [url]www.icaam.com.ar[/url]
    Note: The information inside this message and also in the attached files
    might be confidential. If you are not the desired receptor or the person
    responsible of delivering the message, we notify you that it's copy,
    distribution, keep or illegal use of the information it has it's
    prohibited. Therefore we ask you to notify the sender by replying this
    message immediately and then delete it from your computer.


    Cesar Aracena Guest

  6. #5

    Default Checkboxes

    Okay, I've only been doing php/mysql for a few months and I admit to
    being a little stumped on this one.

    I have a form which posts updates to a mysql table. I'd like to use
    checkboxes to show and update boolean type values. In Access it's very
    simple to create a field of type Yes/No, bind a form to the table, and
    bind a checkbox object to the Yes/No field. I am unable to find generic
    examples of this in php/mysql.

    1. What field type should I use in a mysql table?
    2. When the php<html><form> loads the data from the selected record,
    what is the generic syntax for initializing the check box?

    'bonehead Guest

  7. #6

    Default Re: Checkboxes

    'bonehead <senmenospam@here.org> writes:
    > I have a form which posts updates to a mysql table. I'd like to use
    > checkboxes to show and update boolean type values. In Access it's very
    > simple to create a field of type Yes/No, bind a form to the table, and
    > bind a checkbox object to the Yes/No field. I am unable to find generic
    > examples of this in php/mysql.
    >
    > 1. What field type should I use in a mysql table?
    MySQL has a BOOL type but it's just a synonym for TINYINT(1).
    Another possibility would be ENUM.
    > 2. When the php<html><form> loads the data from the selected record,
    > what is the generic syntax for initializing the check box?
    Here's one way:

    // Set the variable $foo from the database or from form data.
    $checked = $foo ? "checked" : "";
    echo "<input type=\"checkbox\" name=\"foo\" $checked>";

    Or later if you're outside PHP:

    <input type="checkbox" name="foo" <?php echo $checked?>>

    Or you could omit the $checked variable:

    <input type="checkbox" name="foo" <?php echo $foo ? "checked" : ""?>>

    There are several ways to do this; the important thing is to print
    the "checked" attribute if the boolean variable is on/true.

    --
    Michael Fuhr
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  8. #7

    Default Re: Checkboxes

    "Michael Fuhr" <mfuhr@fuhr.org> wrote in message
    news:3fc43cf0$1_3@omega.dimensional.com...
    > 'bonehead <senmenospam@here.org> writes:
    >
    > $checked = $foo ? "checked" : "";
    Although, in the newer implementations of HTML, that would be

    $checked = $foo ? 'checked="true"' : '';

    Christopher Finke


    Christopher Finke Guest

  9. #8

    Default Re: Checkboxes

    "Christopher Finke" <christopherfinke@hotmail.usenet.com> writes:
    > "Michael Fuhr" <mfuhr@fuhr.org> wrote in message
    > news:3fc43cf0$1_3@omega.dimensional.com...
    > > 'bonehead <senmenospam@here.org> writes:
    > >
    > > $checked = $foo ? "checked" : "";
    >
    > Although, in the newer implementations of HTML, that would be
    >
    > $checked = $foo ? 'checked="true"' : '';
    Shouldn't that be 'checked="checked"'? That's what the XHTML 1.0
    DTD appears to require, and using "true" causes XHTML 1.0 and 1.1
    documents to fail validation at validator.w3.org.

    --
    Michael Fuhr
    [url]http://www.fuhr.org/~mfuhr/[/url]
    Michael Fuhr Guest

  10. #9

    Default Re: Checkboxes

    Michael Fuhr wrote:
    > Here's one way:
    >
    > // Set the variable $foo from the database or from form data.
    > $checked = $foo ? "checked" : "";
    > echo "<input type=\"checkbox\" name=\"foo\" $checked>";
    >
    > Or later if you're outside PHP:
    >
    > <input type="checkbox" name="foo" <?php echo $checked?>>
    Got it working...thanks. The exact syntax for the checked argument is
    where I was getting stumped.

    Meanwhile, I came up with another fairly trivial question. I'll post it
    under the heading "Textarea Formatting".

    bonehead Guest

  11. #10

    Default checkboxes

    :confused;

    I have developed a roster sign-up list on my website. I want visitors to be
    able to go in, check off their names, and have that infomation remain on the
    site for everyone to see. As each players updates the site, I want the
    checkboxes to remain clicked. Right now, the checkboxes turn blank on refresh.
    Is there a way I can add a checkbox that will "stay checked" once it's been
    clicked? Maybe using Javascript?

    Thanks

    jasperm Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139