How do you show Dropdown menu selected value in edit user page | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| |
Hello,
I have an edit user page that allows the user to view their user information and make changes if possible. I have a simple html login page that directs to an asp page called edituser.asp when they login. Here is the edituser.asp code I have - <%@ Language=VBScript %>
-
<% Option Explicit %>
-
<!--#include virtual="/adovbs.inc"-->
-
<html>
-
<body>
-
<%
-
Dim oConn, oRs
-
Dim connectstr, sDSNDir, tablename
-
Dim db_name, db_username, db_userpassword
-
Dim dsn_name
-
-
dsn_name = "register.dsn"
-
tablename = "tblRegister"
-
db_username = "****"
-
db_userpassword = "****"
-
-
sDSNDir = Server.MapPath("/_dsn")
-
connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
-
-
Set oConn = Server.CreateObject("ADODB.Connection")
-
oConn.Open connectstr
-
-
Dim objRS, bolFound, strEmail
-
strEmail = Request.Form("email")
-
-
If strEmail = "" Then
-
oConn.Close
-
Set objConn = Nothing
-
Response.Write "<a href='login.html'>"
-
Response.Write "You must enter a email address"
-
Response.Write "</a>"
-
Response.End
-
End If
-
-
Set objRS = Server.CreateObject("ADODB.Recordset")
-
objRS.Open "tblRegister", oConn, , , adCmdTable
-
bolFound = False
-
-
Do While Not (objRS.EOF OR bolFound)
-
If (StrComp(objRS("Email"), strEmail, vbTextCompare) = 0) Then
-
BolFound = True
-
Else
-
objRS.MoveNext
-
End If
-
Loop
-
-
If Not bolFound Then
-
objRS.Close
-
Set objRS = Nothing
-
oConn.Close
-
Set oConn = Nothing
-
Response.Write "<a href='login.html'>"
-
Response.Write "Invalid Email Address.<p>"
-
Response.Write "</a>"
-
Response.End
-
End If
-
-
If Not (StrComp(objRS("Password"), Request.Form("password"), _
-
vbBinaryCompare) = 0) Then
-
objRS.Close
-
Set objRS = Nothing
-
oConn.Close
-
Set oConn = Nothing
-
Response.Write "<a href='login.html'>"
-
Response.Write "Invalid password.<p>"
-
Response.Write "</a>"
-
Response.End
-
End If
-
%>
-
-
<!-- create form, fill with values from table -->
-
<form method=post action="modifyuser.asp">
-
<p>
-
State: <select name=state type=text value="<%=objRS("State")%>">
-
<option selected="state">Choose State</option>
-
<option value="AL">AL</option>
-
<option value="AR">AR</option>
-
<option value="AZ">AZ</option>
-
<option value="CA">CA</option>
-
<option value="CO">CO</option>
-
<option value="CT">CT</option>
-
<option value="DC">DC</option>
-
</select>
-
<p>
-
<input type=reset> <input type=submit>
-
</form>
-
</body>
-
</html>
-
<%
-
objRS.Close
-
Set objRS = Nothing
-
oConn.Close
-
Set oConn = Nothing
-
%>
In this code, I simply allow the user to edit their "State". When the user registers, they choose a state which is stored in my database. However, when I go to the edituser.asp page, it just shows "Choose State". How do I get the edituser.asp page to show which state they said they were from when they registered?
thanks - Jerry
| | Newbie | | Join Date: Nov 2008
Posts: 1
| | | re: How do you show Dropdown menu selected value in edit user page
Use javascript at the bottom of your page, something like this:
<script type="text/javascript">
document.form.state.value = "<%=state%>";
//etc..
</script>
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: How do you show Dropdown menu selected value in edit user page
Jerry,
Azrar's suggestion works (and might be the best approach), but if you want an ASP solution, it would look something like this: - <select name=state type=text>
-
<option>Choose State</option>
-
<option value="AL"
-
<% if objRS("state") = "AL" then response.write "SELECTED" %>
-
>AL</option>
-
<option value="AR"
-
<% if objRS("state") = "AR" then response.write "SELECTED" %>
-
>AR</option>
-
<option value="AZ"
-
<% if objRS("state") = "AZ" then response.write "SELECTED" %>
-
>AZ</option>
-
<option value="CA"
-
<% if objRS("state") = "CA" then response.write "SELECTED" %>
-
>CA</option>
-
<option value="CO"
-
<% if objRS("state") = "CO" then response.write "SELECTED" %>
-
>CO</option>
-
<option value="CT"
-
<% if objRS("state") = "CT" then response.write "SELECTED" %>
-
>CT</option>
-
<option value="DC"
-
<% if objRS("state") = "DC" then response.write "SELECTED" %>
-
>DC</option>
-
</select>
Of course if you had the list of states in an array or some other form that you could loop through them, that would make it significantly easier.
Jared
|  | Expert | | Join Date: Oct 2008 Location: Bristol, United Kingdom
Posts: 145
| | | re: How do you show Dropdown menu selected value in edit user page
If your option group comes from a database, then you can do as I usually do: -
<select name="txtState">
-
<% Do While Not stateRS.EOF
-
If stateRs("statename") = userRS("state") Then %>
-
<Option selected><%=stateRs("typename")%></option>
-
<% Else %>
-
<Option><%=CatRs("statename")%></option>
-
<% End If
-
stateRs.MoveNext()
-
Loop %>
-
</select>
-
Gaz
| | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| | | re: How do you show Dropdown menu selected value in edit user page
You guys are the best. Thank you so very much for all of your reponses and help.
I ended up using jhardman's suggestion because it seemed to fit into my page the best. And it works exactly the way I had hoped.
Have a great day.
Jerry
| | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| | | re: How do you show Dropdown menu selected value in edit user page
Hi, I have a follow up question.
I also have a checkbox section in my edit user information section that I would like to show the user's registration choice on the edituser.asp page.
Currently, it is empty no matter what the user entered during registration
How do I code this so that a check mark will show up if they originally checked the box during registration?
Thanks
|  | Expert | | Join Date: Oct 2008 Location: Bristol, United Kingdom
Posts: 145
| | | re: How do you show Dropdown menu selected value in edit user page
Well, Selects have a property called "selected", and check boxes have a similar property called "checked", so therein lies your clue. - <% If rs("somefield") = true Then %>
-
<input type="checkbox" name="chkSubscribed" value="subscribed" checked>
-
<% Else %>
-
<input type="checkbox" name="chkSubscribed" value="subscribed">
-
<% End If %>
Gaz.
| | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| | | re: How do you show Dropdown menu selected value in edit user page
Thanks Gaz.
I tried the following code but it isn't working for me. I think I might have the name or value incorrect.
I am using the name of the checkbox -"nonewsemail"- for the input name and left "subscribed" for the value as seen in the code below. Is that correct? If not, what am I supposed to use.
thanks again for all your help, I really appreciate it.
Jerry - Please check here to opt out of receiving the monthly newsletter:
-
<% If objRS("nonewsemail") = true Then %>
-
<input type="checkbox" name="nonewsemail" value="subscribed" checked />
-
<% Else %>
-
<input type="checkbox" name="nonewsemail" value="subscribed" />
-
<% End If %>Please check here to opt out of receiving the monthly newsletter:
-
<% If objRS("nonewsemail") = true Then %>
-
<input type="checkbox" name="nonewsemail" value="subscribed" checked />
-
<% Else %>
-
<input type="checkbox" name="nonewsemail" value="subscribed" />
-
<% End If %>
|  | Expert | | Join Date: Oct 2008 Location: Bristol, United Kingdom
Posts: 145
| | | re: How do you show Dropdown menu selected value in edit user page
I really can't say why that's not working for you (did you mean to paste the code twice?).
I suggest you Response.Write your nonewsemail variable, to see what it contains.
| | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| | | re: How do you show Dropdown menu selected value in edit user page
I'm sorry about the last post, I accidently put the script in twice. Here is the script I am using. It won't work for some reason.
I am not sure how to do the Response.Write function you speak of.
My form shows up with a checkbox but everytime I try to edit this and include a checkmark in the box, it goes through with the edit but doesn't show the box as checked when I re-visit the edit user page.
Could it possible be the way my access field is set up? I have it set to text and don't required anything to be entered. - Please check here to opt out of receiving the monthly newsletter:
-
<% If objRS("nonewsemail") = true Then %>
-
<input type="checkbox" name="nonewsemail" value="" checked>
-
<% Else %>
-
<input type="checkbox" name="nonewsemail" value="">
-
<% End If %>
|  | Expert | | Join Date: Oct 2008 Location: Bristol, United Kingdom
Posts: 145
| | | re: How do you show Dropdown menu selected value in edit user page
If your field was set up as text that makes sense, what happens if you change the database field to Yes/No type?
BTW, all I meant before was: - <%
-
Response.Write "<p>Dubug nonewsemail: " & ObjRs("nonewsemail") & "</p>"
-
%>
to see what comes from the database.
When putting booleans back in to the database via a checkbox, you should convert the value. I keep this handy: - function ChkToBool(value)
-
if ucase(value)="ON" then
-
ChkToBool=true
-
else
-
ChkToBool=false
-
end if
-
end function
Which is then used like, for example: -
rs("SomeField")=ChkToBool(request("SomeCheckBox"))
-
rs.Update
-
|  | Forum Leader | | Join Date: Jul 2006 Location: Oklahoma
Posts: 1,076
| | | re: How do you show Dropdown menu selected value in edit user page
if your database says
on / off in the column you need to check against "on" or "off" not true/false
if it says
1 / 0 you can test this with true or false
if it says
true / false then you gotta test it with "true" or "false"
|  | Expert | | Join Date: Oct 2008 Location: Bristol, United Kingdom
Posts: 145
| | | re: How do you show Dropdown menu selected value in edit user page Quote:
Originally Posted by iam_clint if your database says
on / off in the column you need to check against "on" or "off" not true/false
if it says
1 / 0 you can test this with true or false
if it says
true / false then you gotta test it with "true" or "false" Well, its Access, so yes/no - which compares with true/false. At least it does for me.
| | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| | | re: How do you show Dropdown menu selected value in edit user page
Thanks for the input.
Well, I got the edituser page to work. I just had to change the field box in my access table to "yes/no" instead of "text".
However, when I do so, my registration.asp page shows an error. When I sumbit the registration, I get an error pointing me to my asp page line that reads - objRS("NoNewsEmail") = Request.Form("nonewsemail")
I don't understand why this error occurs once I change the access table field to yes/no. "NoNewsEmail" is the column in my access table, and "nonewsemail" is the input name for the form checkbox section.
Any ideas why this is happening?
|  | Expert | | Join Date: Oct 2008 Location: Bristol, United Kingdom
Posts: 145
| | | re: How do you show Dropdown menu selected value in edit user page
I refer you to my post number 11.
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: How do you show Dropdown menu selected value in edit user page Quote:
Originally Posted by jerrydigital Thanks for the input.
Well, I got the edituser page to work. I just had to change the field box in my access table to "yes/no" instead of "text".
However, when I do so, my registration.asp page shows an error. When I sumbit the registration, I get an error pointing me to my asp page line that reads - objRS("NoNewsEmail") = Request.Form("nonewsemail")
I don't understand why this error occurs once I change the access table field to yes/no. "NoNewsEmail" is the column in my access table, and "nonewsemail" is the input name for the form checkbox section.
Any ideas why this is happening? Markrawlingson wrote an article on this subject. It pretty much covers all the issues and how to avoid the problem.
Jared
| | Member | | Join Date: Oct 2008 Location: Cleveland Ohio
Posts: 67
| | | re: How do you show Dropdown menu selected value in edit user page
Thank you all for your great explanations and help.
I ended up just using a drop down menu where the user enters yes or no. I took the easy way out and I am not pleased with that but I am under time constraints. Hopefully I will get some time in the future to revisit this question and put all of your tips to use. Thanks again for your help on this matter, I truely appreciate all of it.
Jerry
| | Newbie | | Join Date: Jul 2008
Posts: 30
| | | re: How do you show Dropdown menu selected value in edit user page
This post is helpful. I had the same problem and now solved.
|  | Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,471 network members.
|