4 Replies - 6450 Views - Last Post: 21 September 2011 - 09:49 AM

#1 jrb47  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 21-April 07

checkbox to pass data not working

Posted 08 September 2011 - 07:34 PM

I generally do not work in asp however I am working on a project for a volunteer student org - they are working with pregnant teens.

I have the following code and while I can get the names and address to pass I can not get the checkbox to pass true or 1 when checked.
regardless of what I try the data is registering as False - which tells me that a true value is not being passed correctly.

below is both the aspx code and the html code

aspx
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
     
    <script language="VB" runat="server">
     
    Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
     
    Dim objConnection As OleDbConnection
    Dim objCmd As OleDbCommand
    Dim strConnection As String
    Dim strSQL As String
     
    strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=Teens.mdb"
     
    ' Create and open the connection object
    objConnection = New OleDbConnection(strConnection)
    objConnection.Open()
     
     
    strSQL = "INSERT INTO teens(Pname, Paddress, Delivered) VALUES (?, ?, ?)"
     
     
    ' Create the Command and set its properties
    objCmd = New OleDbCommand(strSQL, objConnection)
    objCmd.Parameters.Add(New OleDbCommand("text1", Request.Form("text1")))
    objCmd.Parameters.Add(New OleDbCommand("text2", Request.Form("text2")))
    objCmd.Parameters.Add(New OleDbCommand("text3", If(Request.Form("text3") IsNot Nothing AndAlso Request.Form("text3").Lenth > 0, Request.Form("text3"), "False")))
    ' execute the command
    objCmd.ExecuteNonQuery()
     
    lblStatus.Text = "Command run"
     
    End Sub
     
    </script>
     
    <html>
    <body>
    <h2>Insert Data into Table</h2>
    <asp:Label id="lblStatus" runat="server"/>
    <p>
     
    </body>
     
    </html>
     



html form Code
    <html>
     
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 1</title>
    </head>
     
    <body>
    <form runat="server" action = "InsertNames.aspx" method = "post">
     
    Please enter Patients Name:
    <input type = "Text" name = "text1" style="color: red" size="20" />
    <br /><br />
     
    Please enter Patients Address:
    <input type = "Text" name = "text2" style="color: red" size="20" />
    <br /><br />
     
    Delivered:
    <input id="text3" type="checkbox" value="True" />
     
    <br /><br />
    <input type="Submit">
    </form>
     
    </body>
     
    </html>



Is This A Good Question/Topic? 0
  • +

Replies To: checkbox to pass data not working

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,186
  • Joined: 02-June 10

Re: checkbox to pass data not working

Posted 09 September 2011 - 12:53 PM

<input id="text3" type="checkbox" value="True" />



I don't do web stuff, so this may be way off.
But wouldn't a checkbox.Checked be a bool and a value of True not "True" ?

true rather than True ??

checkbox.checked instead of just checkbox ?

You may have to play around with it a bit to find the exact syntax.
I usually keep all my failed attempts as comments so I don't keep retrying the same things.

//<input id="text3" type="checkbox" value="True" />
//<input id="text3" type="checkbox" value="true" />
//<input id="text3" type="checkbox" value=true />
//<input id="text3" type="checkbox.Checked" value=true />
//<input id="text3" type="checkbox.Checked" value="True" />
//<input id="text3" type="checkbox" value="True" />
// and so on until I find the right syntax


Was This Post Helpful? 0
  • +
  • -

#3 Nakor  Icon User is offline

  • Professional Lurker
  • member icon

Reputation: 446
  • View blog
  • Posts: 1,501
  • Joined: 28-April 09

Re: checkbox to pass data not working

Posted 10 September 2011 - 08:33 PM

is there a reason you're not using server controls for that form? Why are you using an <input type="checkbox" .. instead of an <asp:CheckBox .. control?
Was This Post Helpful? 0
  • +
  • -

#4 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 203
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: checkbox to pass data not working

Posted 21 September 2011 - 09:32 AM

Line 28 in your posted code should throw you a syntax error.
You spelled "Length" as "Lenth".


-Frinny

This post has been edited by Frinavale: 21 September 2011 - 09:37 AM

Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5674
  • View blog
  • Posts: 12,186
  • Joined: 02-June 10

Re: checkbox to pass data not working

Posted 21 September 2011 - 09:49 AM

Oh I so hate it when people post code they haven't even used/debugged.

It just shows they aren't really trying to solve their own issue. But instead trying to have someone write a working algorithm for them.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1