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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Oct 2003
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form 'checkbox' to return a value if it is not ticked?

    I need a few check boxes to return a value if they are not checked.

    e.g...

    if the tick the 'box1' the form returns the value ...
    box1=YES
    if you don't tick 'box1' the form returns the value ...
    box1=NO

    Here's the HTML page so far ...

    <script language="JavaScript" type="text/JavaScript">
    function DoCheck() {
    if(document.form.box1.checked == false)
    (document.form.box1.value = "NO");
    if(document.form.box2.checked == false)
    (document.form.box2.value = "NO");
    }
    </script>

    <title>Form Test</title>
    </head>

    <form action="mailer.asp" method="post" name="form">
    <input name="_recipients" type="hidden" value="animations@ntlworld.com">
    <input name="_replyToField" type="hidden" value="Email">
    <input name="_subject" type="hidden" value="Form Test">
    <input name="_redirect" type="hidden" value="test.htm">
    <input type="checkbox" name="box1" value="YES">
    <input type="checkbox" name="box2" value="YES">
    <input type="submit" onClick="DoCheck()">
    </form>

  • #2
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, not gonna happen. That's just the way HTML Forms work. You should validate all incoming fields in your server-side script anyway; if you absolutely require a value be passed, use radio buttons and preselect one.

  • #3
    New to the CF scene
    Join Date
    Oct 2003
    Location
    UK
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would it be possible to dynamically create a hidden field if a checkbox has not been ticked? ... (i.e. have a hidden field that is updated by the status of a checkbox). At the moment NOTHING is sent to the form unless a checkbox is ticked. For auditing reasons I need a 'NO' sent to the mail-script if the box isn't ticked ...

    Oh, the client is adament that they are checkboxes.
    ... I guess they don't want their clients to actually have the direct option to select 'NO'

  • #4
    Regular Coder
    Join Date
    Jul 2003
    Location
    NJ - #29 if you must know
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well one way is to have a checkbox under a different name,
    and have a hidden text field with the original name

    and prior to submitting the form, check if the checkbox
    has been checked, and set hidden value to YES,
    if not set to NO, then reset the checkbox to false,
    so it doesn't get returned,

    George

    Ex. If checkbox name is "WANTSPAM" make it say
    WANTSPAM-CK,

    and have a HIDDEN TEXT field NAME="WANTSPAM"

    Have an OnSubmit="" event in the form, which
    will check WANTSPAM-CK.checked for true and
    assign "YES" to WANTSPAM, otherwise assign "NO"
    to WANTSPAM, then set WANTSPAM-CK.checked to
    false.

    George

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    when a checkbox is not checked, it will not be submitted to the server. That is really the behavior of checboxes, radios, single selects.

    If you request.form a checkbox and it has no value, it means that it is not checked.

    chk = request.form("checkboxname")
    if chk <>"" then
    'checked
    else
    'not checked, do something
    end if
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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