Retrieving status of checkbox on form

Results 1 to 10 of 10

Thread: Retrieving status of checkbox on form

  1. #1
    Join Date
    Dec 1969
    Posts
    168

    Default Retrieving status of checkbox on form

    I have a checkbox named "Mgmt" and am trying to retrieve the status of it when posting to an asp page (via vbscript). When I do a:<BR>&#060;% Dim Mgmt<BR>Mgmt = Request.Form("Mgmt")&#037;&#062;<BR>The value is:"&#060;%=Mgmt&#037;&#062;"<BR><BR><BR>I get &#039The value is:""&#039 regardless of the state of the checkbox. Other form elements are coming through fine, but none of the check boxes... Can anyone offer some insight on this matter?<BR>

  2. #2
    Bijal Guest

    Default RE: Retrieving status of checkbox on form

    Try this out:<BR><BR>&#060;% Dim Mgmt<BR>If Request.Form("Mgmt")="on" Then<BR> Mgmt = "Checked" &#039 or whatever status you want &#039 like 1.<BR>Else<BR> Mgmt = "Not Checked" &#039 or whatever status you want &#039 like 0.<BR>End If<BR><BR>Hope this works fine for you.<BR><BR>Bijal.<BR>

  3. #3
    Join Date
    Dec 1969
    Posts
    168

    Default RE: Retrieving status of checkbox on form

    I tried your suggestion.. (see code below) but regardless of the state of the check box the value of Mgmt was always set to "No".<BR><BR>&#060;% Dim Mgmt<BR>if (Request.Form("Mgmt")="on") then <BR> Mgmt="Yes" <BR>else <BR> Mgmt="No" <BR>end if &#037;&#062;<BR>Value of Mgmt is: &#060;%=Mgmt&#037;&#062;

  4. #4
    Bijal Guest

    Default RE: Retrieving status of checkbox on form

    Try writing "True" instead of "on"<BR>Also "Mgmt" should be the NAME of the input type which is Checkbox.<BR>For example:<BR>&#060;Input type=CHECKBOX name=Mgmt ><BR>so remove<BR>&#039Dim Mgmt&#039 from your code.<BR><BR>try this out now:<BR>&#060;% if (Request.Form("Mgmt")="True") then <BR> Mgmt="Yes" <BR> else <BR> Mgmt="No" <BR> end if<BR>&#037;&#062;<BR>Value of Mgmt is: &#060;%=Mgmt&#037;&#062;<BR><BR>i guess that should work.<BR><BR>Bijal.<BR>


  5. #5
    Join Date
    Dec 1969
    Posts
    168

    Default Still doesn't work

    I&#039ve tried "True" "On" "Yes" in combinations of capitalizations.. nothing seems to capture the status of the checkbox.

  6. #6
    Join Date
    Dec 1969
    Posts
    197

    Default RE: Still doesn't work

    I&#039m just curious, I&#039m doing sort the same thin. have yo assigned it a value. try assigning it a value.<BR><BR>&#060;input type=checkbox value=false><BR>

  7. #7
    Join Date
    Dec 1969
    Posts
    168

    Default RE: Assigning value doesn't work either

    &#060;input type="checkbox" value="[true&#124false&#124yes&#124no]" [Checked]> (where the items in []&#039s are optional) Still does not allow me to retrieve the status of the checkbox...<BR><BR>Hoping someone out there has a solution ...

  8. #8
    su Guest

    Default RE: Assigning value doesn't work either

    if you have a checkbox item in your form : _use this;_<BR>&#060;input type="checkbox" name="check" value="what you want"><BR>and if submit this form <BR>a checkbox item returns a checkbox array of checked ones.<BR>the value returned is request.form("check") and because of this<BR>you get "" when you try to get that.<BR>if you use : for example<BR>&#060;% if request.form("check").count > 0 then<BR>the value=on<BR>else<BR>the value=off<BR>end if&#037;&#062;<BR>or one more<BR>&#060;%ref=request.form("check").count<BR> if ref &#060;> 0 then ....&#037;&#062; <BR>Hope it helps.if it fails try a bit changing this.<BR>Su..

  9. #9
    Bijal Guest

    Default Thanks Su, your trick worked for me.

    Thanks Su, now i am able to update the status of my checkboxes as well. i had spent a whole week after this but didn&#039t get the solution. <BR><BR>Thanks a lot again.<BR><BR>Bijal

  10. #10
    Join Date
    Dec 1969
    Posts
    168

    Default The Checkbox solution....

    This is the solution i ended up using to figure out what the status of the checkbox was...<BR><BR>&#060;% <BR>if (CInt(Request.Form("Checkbox_Name") = "on") = -1) then <BR>checkboxstatus="Checked" &#039 Set to yes/true/whatever<BR>else <BR>checkboxstatus="Not Checked" &#039 Set to no/false/whatever<BR>end if <BR>Response.Write("The check box status is: " & checkboxstatus)<BR>&#037;&#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
  •