#1
  1. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2010
    Posts
    88
    Rep Power
    5

    updating database only when a check box is displayed


    I have a classic asp code page where i hide and show a check box based on a database feild value.It is working fine when the checkbox is displayed and the page is submitted.but when the check box is not displayed because it did not meet a requirement and when i submit the page it is inserting null into the database for a feild.

    how do i change the program such that it updates the database only when the control is displayed and it should not update anything when the control is not being displayed


    i have a separate database page on which i get the checkbox control using

    vTagCustomer = Request.Form("tagcustomer")

    Below is the code i have been using to update the database when the check box is checked or not

    if not isnull(vTagCustomer) and not vTagCustomer= "" then
    SQLStmt = "exec dbo.CUSTOMERTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU4 = Connection.Execute(SQLStmt)
    Set RRU4 = NOTHING
    else
    SQLStmt = "exec dbo.CUSTOMERUNTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU5 = Connection.Execute(SQLStmt)
    Set RRU5 = NOTHING

    end if

    I need the above code to work only if the control tagcustomer is displayed on the code page?

    Thanks
  2. #2
  3. Contributing User
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Mar 2005
    Location
    Columbus, OH
    Posts
    1,581
    Rep Power
    278
    I believe it will be much easy to add hidden field on your page and just check value for decision about update data or not....
    <input type = "hidden" name="uneatable" value="N" />

    <%
    if request("uneatable")="Y" then
    ' your update code
    end if
    %>
    you set original value in asp code and / or change value inside that field with javasript
    GK
    __________________________________________________ _____
    if you found this post is useful click Give Rep button (bottom side on this reply ) and agree
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2010
    Posts
    88
    Rep Power
    5
    Can you please eloborate on your help

    how and why will a hidden feild help in my scenario

    the below is the code that i am using to hide and unhide a table column

    Code:
    <%if (vrptdesc6="Y") then %>
          <td colspan="2"> Tag Customer for no reporting &nbsp; &nbsp;
            <input type="checkbox" name="tagcustomer" id= "tagcustomer"  <%if vCustFlag = "Y" then %>checked <%end if%>    value = "Y"  /> </td>
             <% End If %>

    will i be able to use the vrptdesc6 value to enable and disable database code.Iam new to coding world

    the database code is not in the same page as the asp code.It is in a separate file
    Originally Posted by gk53
    I believe it will be much easy to add hidden field on your page and just check value for decision about update data or not....
    <input type = "hidden" name="uneatable" value="N" />

    <%
    if request("uneatable")="Y" then
    ' your update code
    end if
    %>
    you set original value in asp code and / or change value inside that field with javasript
  6. #4
  7. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    Code:
    <%if (vrptdesc6="Y") then %>
          <td colspan="2"> Tag Customer for no reporting * *
            <input type="checkbox" name="tagcustomer" id= "tagcustomer"  <%if vCustFlag = "Y" then %>checked <%end if%>    value = "Y"  /> </td>
    <% else %>
     <input type="hidden" name="tagcustomer" id= "tagcustomer"  value = "bypass">
             <% End If %>
    if vTagCustomer&"" <> "" and vTagCustomer <> "bypass" then
    SQLStmt = "exec dbo.CUSTOMERTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU4 = Connection.Execute(SQLStmt)
    Set RRU4 = NOTHING
    else
    SQLStmt = "exec dbo.CUSTOMERUNTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU5 = Connection.Execute(SQLStmt)
    Set RRU5 = NOTHING

    end if

    The &"" takes care of null or empty strings in one shot.
  8. #5
  9. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    Be nice if this crappy editor had an edit option. This might be better:

    Code:
    <%if (vrptdesc6="Y") then %>
          <td colspan="2"> Tag Customer for no reporting * *
            <input type="checkbox" name="tagcustomer" id= "tagcustomer"  <%if vCustFlag = "Y" then %>checked <%end if%>    value = "Y"  /> </td>
    <% else %>
     <input type="hidden" name="tagcustomer" id= "tagcustomer"  value = "bypass">
             <% End If %>
    if vTagCustomer <> "bypass" then
    if not isnull(vTagCustomer) and not vTagCustomer= "" then
    SQLStmt = "exec dbo.CUSTOMERTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU4 = Connection.Execute(SQLStmt)
    Set RRU4 = NOTHING
    else
    SQLStmt = "exec dbo.CUSTOMERUNTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU5 = Connection.Execute(SQLStmt)
    Set RRU5 = NOTHING

    end if
    end if
  10. #6
  11. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    Argh! Three times to get it right. The above won't work because even upon deselecting the box the untag won't get processed.


    <%if (vrptdesc6="Y") then %>
    <td colspan="2"> Tag Customer for no reporting * *
    <input type="checkbox" name="tagcustomer" id= "tagcustomer" <%if vCustFlag = "Y" then %>checked <%end if%> value = "Y" /> </td>
    <% else %>
    <input type="hidden" name="bypass" value = "yes">
    <% End If %>[/CODE]

    if request.form("bypass") <> "yes" then
    if not isnull(vTagCustomer) and not vTagCustomer= "" then
    SQLStmt = "exec dbo.CUSTOMERTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU4 = Connection.Execute(SQLStmt)
    Set RRU4 = NOTHING
    else
    SQLStmt = "exec dbo.CUSTOMERUNTAGGING "
    SQLStmt = SQLStmt & vReqNum & "; "
    Set RRU5 = Connection.Execute(SQLStmt)
    Set RRU5 = NOTHING

    end if
    end if

    Comments on this post

    • jim_jim disagrees : Thank You so much for your help
  12. #7
  13. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2010
    Posts
    88
    Rep Power
    5
    Thanks.It worked

Similar Threads

  1. Form to Database - Page Cannot Be Displayed
    By atxhou in forum ASP Development
    Replies: 8
    Last Post: January 25th, 2008, 08:34 PM
  2. Recalculating displayed results from database?
    By gparmar in forum ASP Development
    Replies: 2
    Last Post: August 14th, 2007, 09:29 PM
  3. Check box for updating record to 1
    By flashmxfreak in forum ASP Development
    Replies: 16
    Last Post: May 12th, 2006, 06:22 AM
  4. DropdownList initial value displayed using Database
    By KingBeastie in forum .NET Development
    Replies: 5
    Last Post: May 18th, 2005, 05:31 AM
  5. Urgent: How to check value when updating database?
    By eugeneleck in forum ASP Development
    Replies: 2
    Last Post: October 4th, 2004, 02:30 PM

IMN logo majestic logo threadwatch logo seochat tools logo