Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update onClick

Status
Not open for further replies.

haneen97

Programmer
Dec 10, 2002
280
0
0
US
Hi,
I am trying to trigger an update query on a click of a button. I tried few things but I hit a wall. This where I stand now.

The button:
<input name="pUpdate" type="button" id="pUpdate" value="Update" onClick="return pUpdate_Onclick()">


The function:

Function pUpdate_OnClick()
lId = trim(request.form("txtProdId"))
lName = trim(request.form("txtName"))
lCode = trim(request.form("txtCode"))
lType = trim(CLng(request.form("lstType")))
lVolume = trim(request.form("txtVolume"))
lLevel = trim(request.form("txtReOrder"))
lQty = trim(request.form("txtQtyOnHand"))
lCost = trim(request.form("txtUCost"))
lSale = trim(request.form("txtSalePrice"))
lApps = trim(request.form("txtApplications"))
lEffects = trim(request.form("txtSideEffects"))
lLocation = trim(request.form("txtLocation"))
lActive = trim(request.form("txtActiveIng"))
lSName = trim(request.form("txtScientName"))
lNotes = trim(request.form("txtNotes"))
response.Write(lName)
if lName <> "" and lId > 0 then
SqlStr = "UPDATE Product SET Product_Name ='" & lName & "' WHERE Product_Id =" & lId & ";"
MyConn.Execute (SqlStr),,1
end if
end Function

Please help!
Thanks


Mo
 
I changed the code around to do this.

<input name="pUpdate" type="button" id="pUpdate" value="Update Record" onClick="
<%
lId = trim(request.form("txtProdId"))
lName = trim(request.form("txtName"))
lCode = trim(request.form("txtCode"))
lType = trim(CLng(request.form("lstType")))
lVolume = trim(request.form("txtVolume"))
lLevel = trim(request.form("txtReOrder"))
lQty = trim(request.form("txtQtyOnHand"))
lCost = trim(request.form("txtUCost"))
lSale = trim(request.form("txtSalePrice"))
lApps = trim(request.form("txtApplications"))
lEffects = trim(request.form("txtSideEffects"))
lLocation = trim(request.form("txtLocation"))
lActive = trim(request.form("txtActiveIng"))
lSName = trim(request.form("txtScientName"))
lNotes = trim(request.form("txtNotes"))
response.Write(lName)
if lName <> "" and lId <> "" then
SqlStr = "UPDATE Product SET Product_Name ='" & lName & "' WHERE Product_Id =" & lId & ";"
MyConn.Execute (SqlStr),,3
end if

%>

I am not getting an error but the data does not show in the database.

Any idea?

Mo
 
Try this:

SqlStr = "UPDATE Product SET Product_Name ='" & lName & "' WHERE Product_Id ="&lId ;

-DNG
 
Refer to this thread thread333-1046664

onclick you need to call a function and in this function you do the update.

-DNG
 
DotNetGnat
The link has great information but it does not demonstrate how you actually connect to the database server. The function sin that link are demonstrating JScript code only I think.

Mo
 
It seems like you're mixing client side code and server side code. the onClick event is at the client browser, whilst the request.form collection is on the server.

Try this instead..

For the target page of the form
Code:
if request.servervariables("CONTENT_LENGTH") > 0 then
        lId = trim(request.form("txtProdId"))
        lName = trim(request.form("txtName"))
        lCode = trim(request.form("txtCode"))
        lType = trim(CLng(request.form("lstType")))
        lVolume = trim(request.form("txtVolume"))
        lLevel = trim(request.form("txtReOrder"))
        lQty = trim(request.form("txtQtyOnHand"))
        lCost = trim(request.form("txtUCost"))
        lSale = trim(request.form("txtSalePrice"))
        lApps = trim(request.form("txtApplications"))
        lEffects = trim(request.form("txtSideEffects"))
        lLocation = trim(request.form("txtLocation"))
        lActive = trim(request.form("txtActiveIng"))
        lSName = trim(request.form("txtScientName"))
        lNotes = trim(request.form("txtNotes"))
        response.Write(lName)
        if lName <> "" and lId <> "" then
            SqlStr = "UPDATE Product SET Product_Name ='" & lName & "' WHERE Product_Id =" & lId & ";"
            MyConn.Execute (SqlStr),,1
        end if
    end if

The form itself..
Code:
<form action="<%=request.ServerVariables("SCRIPT_NAME")%>" method="POST" name="myform" id="myform">
    <input name="lName" type="text" id="lName" value="-yourname-" />
    <!-- plus other fields that you seem to be looking for in the request.form collection. -->
    <input name="pUpdate" type="Submit" id="pUpdate" value="Update" />
</form>

Or something like that. You will need to modify and test the code above, I've not considered whether you have an actual connection set-up already.. though you seem to infer that in your posted code.

You can also submit the form via javascript if you like.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Hi, thank you all for your help. I think I am close. I think I got the process built. But I think that the variables are not getting the data from the request object. E.g in the line below, the variable is not reading the value from the form. I put the variables in the query string and they are displaying nulls in the url going to the update form.

lName = trim(request.form("txtName"))

Any ideas?


Mo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top