Results 1 to 4 of 4

Thread: checkbox and asp

  1. #1

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    56

    Question

    i have a html form that has 1 textbox and 1 checkbox

    if iwant to check the value (on the server side) the code would look like this (about) response.write request.form("textbox1"), but , (there's always one) what if i want to check the checkbox value.........

    The returned value of a textbox is in the "value" field, but the value of a checkbox seems to be in the "checked" field

    Since the "request.form" only retrieves the value field, how do i proceed for the checked field ?


    thank you all

  2. #2
    Member
    Join Date
    Jun 2000
    Posts
    45
    Are you checking in the same page as the form is on, or are you submitting the form? If you're submitting, then give a value to the checkbox, and that will be passed to the browser IF the box is checked.
    so if the name of the check box is check1, and the value is "bob" then if the checkbox is checked you'll get yoururl/yourpage?check1=bob
    So on the new page you just see if check1 = bob.
    If this doesn't help, post your code.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2000
    Posts
    56

    Smile

    thank you capone: it works

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    This shows how you can test if the checkbox is checked...

    Code:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <%
    dim i
    
    for i = 1 to 5
    	Response.Write("Checkbox " & i & ": " & request("checkbox" & i) & "<BR>")
    	if request("checkbox" & i)= "on" then
    		'this will be true if the checkbox is checked
    	end if
    next
    %>
    <form action="ch.asp">
    <P><INPUT id=checkbox1 name=checkbox1 type=checkbox></P>
    <P><INPUT id=checkbox2 name=checkbox2 type=checkbox></P>
    <P><INPUT id=checkbox3 name=checkbox3 type=checkbox></P>
    <P><INPUT id=checkbox4 name=checkbox4 type=checkbox></P>
    <P><INPUT id=checkbox5 name=checkbox5 type=checkbox></P>
    <INPUT type=submit>
    
    </form>
    </BODY>
    </HTML>
    Mark
    -------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width