• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 255
  • Last Modified:

ASP Edit Form

I have a form that will edit entries in the database. What needs to happen is that with each entry in the database a Radio Button and a Text Field box will appear. The user may only edit one entry per time.

When the user makes their change, the select that radio button. When the user hits submit it fires that and only that entries change to the database.

Any ideas.

Todd
0
yolish
Asked:
yolish
  • 5
  • 3
1 Solution
 
jonathonmcCommented:
Construct the form with radio buttons of the same name and textboxes of unique names. Here's some quick example code:
FIELDS: NAME, PHONE, EMAIL
TABLE: MYTABLE
DSN: MYDSN
ASP: WHATEVER.ASP

<%
if not request.form("SUBMITTED") then
%>
<FORM NAME="test" METHOD="POST" ACTION="WHATEVER.ASP">
<INPUT TYPE="RADIO" NAME="vSELECT" VALUE="name">Name
<INPUT TYPE="TEXT" NAME="vNAME"><BR>
<INPUT TYPE="RADIO" NAME="vSELECT" VALUE="phone">Phone
<INPUT TYPE="TEXT" NAME="vNAME"><BR>
<INPUT TYPE="RADIO" NAME="vSELECT" VALUE="email">Email
<INPUT TYPE="TEXT" NAME="vNAME"><BR>
<INPUT TYPE="HIDDEN" NAME="SUBMITTED" VALUE=1>
<INPUT TYPE="SUBMIT">
</FORM>

<%
else
dim conDB
dim cmdDB
set conDB=server.createobject("ADODB.connection")
set cmdDB=server.createobject("ADODB.command")
conDB.open "DSN=MYDSN"
cmdDB.activeconnection=conDB

select case request.form("vSELECT")
case "name"
cmdDB.commandtext="update mytable set name='" & request.form("vName") & "'"
case "phone"
cmdDB.commandtext="update mytable set phone='" & request.form("vPhone") & "'"
case "email"
cmdDB.commandtext="update mytable set email='" & request.form("vEmail") & "'"
case else
response.write "ERROR"
end select

cmdDB.execute
set cmdDB = nothing
conDB.close
set conDB = nothing
end if%>
0
 
jonathonmcCommented:
Sorry - in that example the textbox names shoule be vName, vPhone, and vEmail respectivly instead of all vName.
0
 
yolishAuthor Commented:
My only question to you is, what happens if that list of radio buttons & text boxes are dynamically created from a database. How would you go about creating you case statement then?
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
jonathonmcCommented:
The select statement tests the value of the radio set - the value can be anything that you want, but it's ties to the text field in the select statement. So if you wanted to dynamically change the text fields, name the radio button i where i is a for i=1 to maxnum loop, then run that same loop in your select statement.
0
 
yolishAuthor Commented:
If you only want one change at a time you need to leave all the names of the radio buttons the same, instead I made a counter on the name of the text field.

This is what I have tried so far

f sAction="edit" Then
      Do While NOT rsLookUp.EOF
      counter=counter+1
            Select Case Request.Form("Lookup_Id")
                  Case 1
                        Response.Write(counter)
                        'sSql2 = "UPDATE Web_Lookup SET lookup_value= '" & sLookup_Value & "' WHERE lookup_id = '" & nFormID & "'"
                        'Vendor.Execute(sSql2)
            End Select
      rsLookUp.MoveNext
      Loop
      'Response.Redirect("/Vendor_relations/search.asp")
End If

With different variations in there
0
 
jonathonmcCommented:
This should work if the counter is also used (and the same sort options) when the avail. fields are pulled from the DB. Otherwise, you would need to use a more static method, like above.

What is the problem with your example? Does it not work?
0
 
yolishAuthor Commented:
I have tried this and several variations of this...


If sAction="edit" Then
      Do While NOT rsLookUp.EOF
      counter=counter+1
            Select Case Request.Form("Lookup_Id")
                  Case 1
                        Response.Write(counter)
                        'sSql2 = "UPDATE Web_Lookup SET lookup_value= '" & sLookup_Value & "' WHERE lookup_id = '" & nFormID & "'"
                        'Vendor.Execute(sSql2)
            End Select
      rsLookUp.MoveNext
      Loop
      'Response.Redirect("/Vendor_relations/search.asp")
End If

It appears the issue is how to you put a dynamic entry in the actual case section..

Thanks
0
 
jonathonmcCommented:
Maybe I'm not understanding the problem, but why not use the numberic value of the recordset in the case section? rsLookUp(0), (1) ...
....using the counter variable?

Otherwise, I must be missing the problem altogether...
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now