Checkboxes and form-submissions

Results 1 to 4 of 4

Thread: Checkboxes and form-submissions

  1. #1
    Christiaan Guest

    Default Checkboxes and form-submissions

    Ok, this is perhaps a rather straight-forward problem, but i can&#039t figure out how to solve it:<BR><BR>I&#039m working on a form-submission handler. When i enter the test-form and hit &#039submit&#039 the data is send to this script.<BR><BR>I use the FOR EACH strfield IN request.form method to cycle through the formfields. The problem occurs with checkboxes. Only if a checkbox is checked will it occur in the cycle. If it is not checked, it will simply not be fetched by the script. How can i solve this problem? Currently, i&#039m using a JScript to change the value of the checkbox to FALSE when it is not checked and check it. This doesn&#039t look very nice (i&#039ve heard a lot of people say &#039hey, why does it check the box anyways??&#039). What can i do about this? is there a way to get around this problem?

  2. #2
    Ian Stallings Guest

    Default RE: Checkboxes and form-submissions

    That is by design. If there is no value for that<BR>checkbox why would you need input from it? If there<BR>is no value assigned to it you can assume that it is <BR>not checked. What are you trying to accomplish. Maybe<BR>someone can come up with a better solution for you.

  3. #3
    icabod Guest

    Default Checkbox properties

    The funny thing about checkboxes is that when they are not checked... rather than return a FALSE value.. they return nothing at all. Unfortunately, that&#039s just the way that the Request.Form collection works..<BR><BR>There are two ways that I know of to fix this problem without making the boxes check themseleves with different values (since you mentioned this is a great source of contention with your clients).<BR><BR>1.) Don&#039t use a for/each loop. Do if/then&#039s for each field manually. I know you were trying to avoid this by using the for/each loop, but sometimes you just have to do this **** by hand. Besides.. you can output in the correct order instead of randomly.<BR><BR>2.) Change up that javascript a little. Create HIDDEN fields next to each checkbox... and have your validator script place a value of TRUE or FALSE in each of those fields on submission. This way, your clients won&#039t see all of their choices changed on a whim.. which should keep those picky bastards happy :). Obviously, there will be duplicate entries for all CHECKED boxes... but you can get around that by telling your for/each loop to ignore the check boxes (so it only uses the HIDDEN fields). If you are going to go that far, you might as well do the first solution.<BR><BR>But that&#039s just my opinion. I could be wrong.<BR><BR><BR>"I&#039m gonna make ASP my *****."

  4. #4
    Join Date
    Dec 1969

    Default RE: Checkboxes and form-submissions

    Use the count property. 0 means not checked.<BR><BR>&#060;%If Request.Form("chk").count = 1 then<BR> strChecked = "Checked"<BR>End if%&#062;<BR>&#060;input type="checkbox" name="chk" id="chk" &#060;%=strChecked%&#062; &#062;

Posting Permissions

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