1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problems retrieving value from textbox

Discussion in 'C#' started by wonder_gal, Oct 26, 2005.

  1. #1
    I was supposed to update some data in database.
    So i have coded my page so that it will display the "data to be changed" in textbox form, allowing user to edit the data in textbox at the same time.
    Then i provide a submit button such that whenever user clicks the submit button, the data changes will be saved into database.

    But now i notice that i cannot even retrieve the textbox value that user has made modifications in. Below is part of my code:

    <html>
    <body>
    <form method="post">

    <%

    Dim sGroup
    Dim sCategory
    Dim sRisk
    Dim sRemark

    Dim dbConnection
    Set dbConnection = Server.CreateObject("ADODB.Connection")
    dbConnection.ConnectionString="Provider=SQLOLEDB.1;UID=sa;Password=password;Initial Catalog=BMI;Data Source=(LOCAL)"
    dbConnection.open

    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open "SELECT * FROM outMessageENContent WHERE msg_bmi_group = '5'", dbConnection

    sCategory = rs("msg_category")
    sRisk = rs("msg_risk")
    sRemark = rs("msg_remark")

    Response.write("Category: <input type='text' name='" & txtCategory & "' size ='30' value='" & sCategory & "'>")
    Response.Write("<BR>")
    Response.Write("Risk: <input type='text' name='" & txtRisk & "' size ='30' value='" & sRisk & "'>")
    Response.Write("<BR>")
    Response.Write("Remark: <input type='text' name='" & txtRemark & "' size ='120' value='" & sRemark & "'>")
    Response.Write("<BR>")

    set rs = Nothing
    dbConnection.Close()
    Set dbConnection = Nothing
    %>

    <input type="submit" value="Save" action = "<%Call updateMessage()%>"/>

    <%
    Function updateMessage()

    Dim sCategory
    Dim sRisk
    Dim sRemark

    sGroup = 5
    sCategory1 = request("txtCategory")
    sRisk1 = request("txtRisk")
    sRemark1 = request("txtRemark")

    response.write "<BR> Category: " &sCategory
    response.write "<BR> Risk: " &sRisk
    response.write "<BR> Remark: " &sRemark
    response.end
    End Function
    %>
    </form>
    </body>
    </html>
    SEMrush
    I cannot print out the new sCategory, sRisk and sRemark at all. Can someone pls help? Thanks alot.
     
    wonder_gal, Oct 26, 2005 IP
    SEMrush
  2. iShopHQ

    iShopHQ Peon

    Messages:
    644
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Well, in your function, you are assign values to variables that all end in 1, while you are writing out variables that don't.

    Also, when you dim a variable inside a function or subroutine, it's treated as a local variable, which means it won't be availabel outside the function or subroutine.

    I suggest dim your variables at the top of the page. Doing so will make them Global, which means they can bring values out of functions and subroutines to the rest of the page.
     
    iShopHQ, Oct 28, 2005 IP
  3. vectorgraphx

    vectorgraphx Guest

    Messages:
    545
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #3
    another thing that might be going on is how you are grabbing your variables, i.e. the sCategory1 = request("txtCategory") is requesting a querystring variable, but your form method is post - which will pass it as a form variable instead of a querystring variable.

    try this instead:
    
    sCategory1 = request.form("txtCategory")
    sRisk1 = request.form("txtRisk")
    sRemark1 = request.form("txtRemark")
    
    
    Code (markup):
    hope that helps you out - looks like you're real close here.

    VG
     
    vectorgraphx, Oct 28, 2005 IP