Another Checkbox Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Corinthian

    Another Checkbox Question

    I am quite new to ASP scripting and seem to be haveing no success with
    checkboxes at all.

    I have a sql database with bit datatypes and I am trying to create a asp
    webform which will display and update the data from checkboxes.

    Any help would be appreciated.

    Rob


  • Ray Costanzo [MVP]

    #2
    Re: Another Checkbox Question

    What exactly are you having trouble with?

    <input type="checkbox" <% If rs.fields.item( 0).value = 1 Then response.write
    " checked"%>>

    Ray at work

    "The Corinthian" <g1ingramstr@bt connect.com> wrote in message
    news:ckj73c$e2b $1@titan.btinte rnet.com...[color=blue]
    >I am quite new to ASP scripting and seem to be haveing no success with
    >checkboxes at all.
    >
    > I have a sql database with bit datatypes and I am trying to create a asp
    > webform which will display and update the data from checkboxes.
    >
    > Any help would be appreciated.
    >
    > Rob
    >[/color]


    Comment

    • Rob

      #3
      Re: Another Checkbox Question

      Hi,

      I am probably mssing some thing I am creating my record set using the
      following

      data connection provided by inc file
      <%
      dim rs
      dim strSQL




      set rs=Server.Creat eObject ("ADODB.Records et")
      strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
      WHERE ID ='" & _
      (Session("useri d")) & "'"


      Set rs = objConn.Execute (strSQL)



      %>

      using



      <input type="checkbox" <% If rs.fields.Item( Arta).value = 1 Then
      response.write" checked"%>>



      Returns
      Error Type:
      ADODB.Fields (0x800A0CC1)
      Item cannot be found in the collection corresponding to the requested name
      or ordinal.
      /dbg12/prefs.asp, line 46



      Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
      message news:OYJaMWSsEH A.220@TK2MSFTNG P15.phx.gbl...[color=blue]
      > What exactly are you having trouble with?
      >
      > <input type="checkbox" <% If rs.fields.item( 0).value = 1 Then
      > response.write " checked"%>>
      >
      > Ray at work
      >
      > "The Corinthian" <g1ingramstr@bt connect.com> wrote in message
      > news:ckj73c$e2b $1@titan.btinte rnet.com...[color=green]
      >>I am quite new to ASP scripting and seem to be haveing no success with
      >>checkboxes at all.
      >>
      >> I have a sql database with bit datatypes and I am trying to create a asp
      >> webform which will display and update the data from checkboxes.
      >>
      >> Any help would be appreciated.
      >>
      >> Rob
      >>[/color]
      >
      >[/color]


      Comment

      • Ray Costanzo [MVP]

        #4
        Re: Another Checkbox Question

        You've got it down just fine with just one small part. You forgot to put
        "Arta" in quotes.

        rs.Fields.Item( "Arta").Val ue
        ''or alternatively
        rs.Fields.Item( 1).Value
        '''Arta is the second column, so it has an index of 1. Column indexes start
        at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2, Newsletter
        is 3.

        I suggest that you get in the habit of using Option Explicit at the top of
        all your VBS-based ASP pages. If you had Option Explicit, the error would
        have been "Variable is not defined - Arta" or something along those lines.

        Ray at work

        "Rob" <anon@robsbiz.c om> wrote in message
        news:1Adbd.111$ oq6.33@newsfe1-gui.ntli.net...[color=blue]
        > Hi,
        >
        > I am probably mssing some thing I am creating my record set using the
        > following[/color]
        [color=blue]
        > set rs=Server.Creat eObject ("ADODB.Records et")
        > strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
        > WHERE ID ='" & _
        > (Session("useri d")) & "'"
        >
        >
        > <input type="checkbox" <% If rs.fields.Item( Arta).value = 1 Then
        > response.write" checked"%>>[/color]
        [color=blue]
        > Returns
        > Error Type:
        > ADODB.Fields (0x800A0CC1)
        > Item cannot be found in the collection corresponding to the requested name
        > or ordinal.
        > /dbg12/prefs.asp, line 46[/color]


        Comment

        • Rob

          #5
          Re: Another Checkbox Question

          Ah sorted - thank you very very much


          "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
          message news:e49Z$vUsEH A.832@TK2MSFTNG P10.phx.gbl...[color=blue]
          > You've got it down just fine with just one small part. You forgot to put
          > "Arta" in quotes.
          >
          > rs.Fields.Item( "Arta").Val ue
          > ''or alternatively
          > rs.Fields.Item( 1).Value
          > '''Arta is the second column, so it has an index of 1. Column indexes
          > start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
          > Newsletter is 3.
          >
          > I suggest that you get in the habit of using Option Explicit at the top of
          > all your VBS-based ASP pages. If you had Option Explicit, the error would
          > have been "Variable is not defined - Arta" or something along those lines.
          >
          > Ray at work
          >
          > "Rob" <anon@robsbiz.c om> wrote in message
          > news:1Adbd.111$ oq6.33@newsfe1-gui.ntli.net...[color=green]
          >> Hi,
          >>
          >> I am probably mssing some thing I am creating my record set using the
          >> following[/color]
          >[color=green]
          >> set rs=Server.Creat eObject ("ADODB.Records et")
          >> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
          >> WHERE ID ='" & _
          >> (Session("useri d")) & "'"
          >>
          >>
          >> <input type="checkbox" <% If rs.fields.Item( Arta).value = 1 Then
          >> response.write" checked"%>>[/color]
          >[color=green]
          >> Returns
          >> Error Type:
          >> ADODB.Fields (0x800A0CC1)
          >> Item cannot be found in the collection corresponding to the requested
          >> name or ordinal.
          >> /dbg12/prefs.asp, line 46[/color]
          >
          >[/color]


          Comment

          • The Corinthian

            #6
            Re: Another Checkbox Question

            I was a bit hasty there - the returning the values is fine now, but now I am
            trying to update them.

            using

            strSQL = "UPDATE preferences SET"
            strSQL = strSQL & "Arta Request.Form("A rta") & "'"
            strSQL = strSQL & " WHERE ID = Session("UserID ")"

            but off course the value "ON" wont go into the bit field, how would I
            convert it so it compatitble.

            Many thanks again.

            Rob
            "Rob" <anon@robsbiz.c om> wrote in message
            news:yZdbd.1462 $8r6.813@newsfe 5-gui.ntli.net...[color=blue]
            > Ah sorted - thank you very very much
            >
            >
            > "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
            > message news:e49Z$vUsEH A.832@TK2MSFTNG P10.phx.gbl...[color=green]
            >> You've got it down just fine with just one small part. You forgot to put
            >> "Arta" in quotes.
            >>
            >> rs.Fields.Item( "Arta").Val ue
            >> ''or alternatively
            >> rs.Fields.Item( 1).Value
            >> '''Arta is the second column, so it has an index of 1. Column indexes
            >> start at zero. So, ID has an index of 0, Arta is 1, Corinthian is 2,
            >> Newsletter is 3.
            >>
            >> I suggest that you get in the habit of using Option Explicit at the top
            >> of all your VBS-based ASP pages. If you had Option Explicit, the error
            >> would have been "Variable is not defined - Arta" or something along those
            >> lines.
            >>
            >> Ray at work
            >>
            >> "Rob" <anon@robsbiz.c om> wrote in message
            >> news:1Adbd.111$ oq6.33@newsfe1-gui.ntli.net...[color=darkred]
            >>> Hi,
            >>>
            >>> I am probably mssing some thing I am creating my record set using the
            >>> following[/color]
            >>[color=darkred]
            >>> set rs=Server.Creat eObject ("ADODB.Records et")
            >>> strSQL = "SELECT ID, Arta, Corinthian, NewsLetter FROM preferences
            >>> WHERE ID ='" & _
            >>> (Session("useri d")) & "'"
            >>>
            >>>
            >>> <input type="checkbox" <% If rs.fields.Item( Arta).value = 1 Then
            >>> response.write" checked"%>>[/color]
            >>[color=darkred]
            >>> Returns
            >>> Error Type:
            >>> ADODB.Fields (0x800A0CC1)
            >>> Item cannot be found in the collection corresponding to the requested
            >>> name or ordinal.
            >>> /dbg12/prefs.asp, line 46[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Ray Costanzo [MVP]

              #7
              Re: Another Checkbox Question

              Give the checkbox a value of 1. Also, you have code enclosed in quotes
              below.

              <input name="chkArta" type="checkbox" value="1"<% If
              CBool(rs.Fields .Item(1).Value) Then Response.Write " checked"%>>

              And then in code:

              <%
              Dim iArta
              iArta = Abs(CBool(Reque st.Form("chkArt a")))
              strSQL = "UPDATE preferences SET YourColumnNameH ere = " & iArta & " WHERE
              [ID] = " & Session("UserID ")
              RESPONSE.WRITE STRSQL
              RESPONSE.END
              %>

              Ray at work



              "The Corinthian" <g1ingramstr@bt connect.com> wrote in message
              news:ckld7r$g06 $1@sparta.btint ernet.com...[color=blue]
              >I was a bit hasty there - the returning the values is fine now, but now I
              >am trying to update them.
              >
              > using
              >
              > strSQL = "UPDATE preferences SET"
              > strSQL = strSQL & "Arta Request.Form("A rta") & "'"
              > strSQL = strSQL & " WHERE ID = Session("UserID ")"
              >
              > but off course the value "ON" wont go into the bit field, how would I
              > convert it so it compatitble.[/color]


              Comment

              • Rob

                #8
                Re: Another Checkbox Question

                Many thanks yet again, I was nearly there, but didn't set a value nor did I
                know about CBool.

                Cheers again.

                Rob

                "Ray Costanzo [MVP]" <my first name at lane 34 dot commercial> wrote in
                message news:%23jAf$1es EHA.820@TK2MSFT NGP12.phx.gbl.. .[color=blue]
                > Give the checkbox a value of 1. Also, you have code enclosed in quotes
                > below.
                >
                > <input name="chkArta" type="checkbox" value="1"<% If
                > CBool(rs.Fields .Item(1).Value) Then Response.Write " checked"%>>
                >
                > And then in code:
                >
                > <%
                > Dim iArta
                > iArta = Abs(CBool(Reque st.Form("chkArt a")))
                > strSQL = "UPDATE preferences SET YourColumnNameH ere = " & iArta & " WHERE
                > [ID] = " & Session("UserID ")
                > RESPONSE.WRITE STRSQL
                > RESPONSE.END
                > %>
                >
                > Ray at work
                >
                >
                >
                > "The Corinthian" <g1ingramstr@bt connect.com> wrote in message
                > news:ckld7r$g06 $1@sparta.btint ernet.com...[color=green]
                >>I was a bit hasty there - the returning the values is fine now, but now I
                >>am trying to update them.
                >>
                >> using
                >>
                >> strSQL = "UPDATE preferences SET"
                >> strSQL = strSQL & "Arta Request.Form("A rta") & "'"
                >> strSQL = strSQL & " WHERE ID = Session("UserID ")"
                >>
                >> but off course the value "ON" wont go into the bit field, how would
                >> I convert it so it compatitble.[/color]
                >
                >[/color]


                Comment

                Working...