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!

request.form value from a drop down

Status
Not open for further replies.

mcallaghan

IS-IT--Management
Mar 22, 2005
43
0
0
US
I have a drop down list which is populated from a mysql database. I should also point out that the drop down value has a value put in there but I want to give the user the opportunity to change it.

For some reason I cant get the value when I click on the button. Below is the code that i am using.

sql= "SELECT user FROM login "
Set rs = conn.execute(sql)
'*****bckuser2 is set to jsmith*******'
response.write "<select name=""Bckuser1"">"
response.write "<option value=" & Bckuser2 & ">" & Bckuser2 & "</option>"
do while not rs.eof
Response.Write "<option value=''" & rs("user") &"''>"& rs("user") &"</option>"
rs.movenext
loop
response.write ("</select>")
%>

<tr>
<!--td><input type="submit" value="Complete Registration"></td-->
<td><INPUT type="submit" name="asubmit" value="Change Registration"></td>


If Request.Form("asubmit") = "Change Registration" then
Response.write "here" &Request.Form("bckUser1")


I cant get the bckuser value.
 
You didn't show the code containing the HTML form.... does it submit to itself?
 
Yes it does get to the if statement. But the Request.Form("bckUser1") is blank
 
Try doing a "View Source" in the broser to make sure the <options> have values.
 
when it gets to this point

Response.write "here" &Request.Form("bckUser1")


it prints out the words here and the rest is blank

here
 
Is the form action set to post rather than get?
 
Can you show more code, more specifically, the code relating to the <form> tag itself? As Sheco suggested earlier, where does your <select> tag fall in relation to the rest of your code? More specifically, does it fall inside of the form itself? I ask because the way you have it framed in your sample above, I wonder if it is outside of this form.

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Here is the code that i am using.

<%
Dim l_name,lokay,l_enter1,lmodsql
dim l_password,rs
If Not Session("loginokays")or l_okay=True Then
Response.Redirect "loginpchange.asp"
else
l_name=Session("Name")
l_name=lcase(l_name)
l_pass=Session("password")
L_GROUP=Session("Group")
l_okay=Session("loginokays")
l_counter=l_counter+1
l_okay=Session("loginokays")
l_enter1="Yes"

strSQL ="SELECT * FROM Login WHERE user='" & l_name & "';"
set myconn = server.createobject("adodb.connection")
connection = "DRIVER={MySQL ODBC 3.51 Driver};
myconn.open (connection)
set result = server.createobject("adodb.recordset")
set result = myconn.execute(strSQL)

Lusers=result("user")
lpassword=result("Password")
L_backup=result("backup")
Bckuser2=result("Bckuser")
ccbname=result("user")
end if

'''' -----------------------------On Save-----------------------------------------'
If Request.Form("asubmit") = "Change Registration" then
Response.write "here" &Request.Form("bckUser1")

if Request.Form("Backup")="on" then
Backup=1
else
Backup=""
end if
bckUser1=Request.Form("bckUser1")
password=Request.Form("password")


' sql ="update login set Password='"&password&"',Backup='"&Backup&"',Bckuser='"&bckUser1&"' WHERE user='" & Lusers & "';"
'set result = myconn.execute(sql)
Set TBL=Nothing
Set DB=Nothing
%>

<html>
<head>
<title>My Website's Registration Page</title>
</head>
<body>
<h1>Member Registration</h1>
<p>Please fill out the following form to register as a member, and
gain access to our members area.</p>
<%=strError%>
<form action="register.asp" method="POST">
<input type="hidden" name="action" value="register">
<table border="0">
<tr>
<td><b>Username</b></td>
<td><input name="username" readonly="readonly" DISABLED value="<%=Lusers%>"></td>
</tr>
<!--td><input type="text" maxlength=20 name="username"
value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td>
</tr-->
<tr>
<td><b>Password</b></td>
<td><input type="password" maxlength=20 name="password"
value="<%=Server.HTMLEncode(lpassword)%>"></td>
</tr>
<tr>
<td><b>Password Confirm</b></td>
<td><input type="password" maxlength=20 name="password_confirm"
value="<%=Server.HTMLEncode(lpassword)%>"></td>
</tr>
<tr>
<td><b>Backup Enabled</b></td>

<%if L_backup="1" THEN %>
<td><input type="CHECKBOX" name="Backup" checked>
<%else%>
<td><input type="CHECKBOX" name="Backup">
<%end if%>

<%
Set conn = server.createobject("adodb.connection")
connection = "DRIVER={MySQL ODBC 3.51 Driver}; conn.open (connection)
set result = server.createobject("adodb.recordset")

sql= "SELECT user FROM login "
Set rs = conn.execute(sql)
response.write "<select name=""Bckuser1"">"
response.write "<option value=" & Bckuser2 & ">" & Bckuser2 & "</option>"
do while not rs.eof
Response.Write "<option value=''" & rs("user") &"''>"& rs("user") &"</option>"
rs.movenext
loop
response.write ("</select>")

response.write bckuser1

%>

<tr>
<!--td><input type="submit" value="Complete Registration"></td-->
<td><INPUT type="submit" name="asubmit" value="Change Registration"></td>
</tr>
</table>
</form>
</body>
</html>


<%
else
%>

<html>
<head>
<title>My Website's Registration Page</title>
</head>
<body>
<h1>Member Registration</h1>
<p>Please fill out the following form to register as a member, and
gain access to our members area.</p>
<%=strError%>
<FORM METHOD="POST" ACTION="register.asp">
<input type="hidden" name="action" value="register">
<table border="0">
<tr>
<td><b>Username</b></td>
<td><input name="username" readonly="readonly" DISABLED value="<%=Lusers%>"></td>
</tr>
<!--td><input type="text" maxlength=20 name="username"
value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td>
</tr-->
<tr>
<td><b>Password</b></td>
<td><input type="password" maxlength=20 name="password"
value="<%=Server.HTMLEncode(lpassword)%>"></td>
</tr>
<tr>
<td><b>Password Confirm</b></td>
<td><input type="password" maxlength=20 name="password_confirm"
value="<%=Server.HTMLEncode(lpassword)%>"></td>
</tr>
<tr>
<td><b>Backup Enabled</b></td>

<%if L_backup="1" THEN %>
<td><input type="CHECKBOX" name="Backup" checked>
<%else%>
<td><input type="CHECKBOX" name="Backup">
<%end if%>
<%
Set conn = server.createobject("adodb.connection")
connection = "DRIVER={MySQL ODBC 3.51 Driver}; conn.open (connection)
set result = server.createobject("adodb.recordset")
sql= "SELECT user FROM login "
Set rs = conn.execute(sql)

response.write "<select name=""Bckuser1"">"
response.write "<option value=" & Bckuser2 & ">" & Bckuser2 & "</option>"
do while not rs.eof
Response.Write "<option value=''" & rs("user") &"''>"& rs("user") &"</option>"
rs.movenext
loop
response.write ("</select>")
%>

<tr>
<!--td><input type="submit" value="Complete Registration"></td-->
<td><INPUT type="submit" name="asubmit" value="Change Registration"></td>
</tr>
</table>
</form>
</body>
</html>
<%
end if
%>
 
Yes it does post to itself. I provided below the code I am using
 
Something Sheco asked earlier was whether you see the values for your options (particularly where they should the values from your database). You said that you see the source code (but not whether you see the option values). Can you please clarify? The reason I ask is because you have separated those values out by using two single quotes to surround the value from the db. I may be off here but I think you should just use two double quotes (as you have elsewhere in the page).
Code:
Response.Write "<option value=[COLOR=red]''[/color]" & rs("user") &"[COLOR=red]''[/color]>"& rs("user") &"</option>"

[COLOR=blue]and they should be[/color]

Response.Write "<option value=[COLOR=red]"[/color]" & rs("user") &"[COLOR=red]"[/color]>"& rs("user") &"</option>"

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
Im not having a problem with seeing the data in the drop down. Its the passing the value that i selected to the save functionality.
 
Seeing the data in the dropdown is not the same thing as seeing the values behind the scenes. Ergo, the reason that we asked about what you see when you click on View Source. You should see that it reads something like:
Code:
<option value="Bob">Bob</option>
If it doesn't read like that, then you are not properly passing the value (which is what you're reading from the request.form variable) to the next page. Does that make sense?

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
<select name="Bckuser1"><option value=></option><option value=''mcallaghan''>mcallaghan</option><option value=''jk''>jk</option><option value=''sa''>sa</option><option </option></select>


This is what i see when i view source there is more names but i deleted all of them
 
Did you try to change the two single quotes to a single double quote (per my post at 9.30 am)? It does not appear to be that way in your source code example above. But I'm not seeing anything else at this point that could be causing the problem...

------------------------------------------------------------------------------------------------------------------------
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened."
- Winston Churchill
 
i GOT IT TO WORK THIS IS WHAT I DID TO MAKE IT WORK

'*****************CHANGED
<select name="select" size="1">
'********************
<%
Set conn = server.createobject("adodb.connection")
connection = "DRIVER={MySQL ODBC 3.51 Driver}; conn.open (connection)
set result = server.createobject("adodb.recordset")
sql= "SELECT user FROM login "
Set rs = conn.execute(sql)

response.write "<option value=" & Bckuser2 & ">" & Bckuser2 & "</option>"
do while not rs.eof
'*****************CHANGED
Response.Write "<OPTION VALUE=""" & rs("user") & """>" & rs("user") & "</OPTION>"
'********************
rs.movenext
loop
%>
</select>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top