473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How do you show Dropdown menu selected value in edit user page

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

Expand|Select|Wrap|Line Numbers
  1. <%@ Language=VBScript %>
  2. <% Option Explicit %>
  3. <!--#include virtual="/adovbs.inc"-->
  4. <html>
  5. <body>
  6. <%
  7. Dim oConn, oRs
  8. Dim connectstr, sDSNDir, tablename
  9. Dim db_name, db_username, db_userpassword
  10. Dim dsn_name
  11.  
  12. dsn_name = "register.dsn"
  13. tablename = "tblRegister"
  14. db_username = "****"
  15. db_userpassword = "****"
  16.  
  17. sDSNDir = Server.MapPath("/_dsn")
  18. connectstr = "filedsn=" & sDSNDir & "/" & dsn_name
  19.  
  20. Set oConn = Server.CreateObject("ADODB.Connection")
  21. oConn.Open connectstr
  22.  
  23. Dim objRS, bolFound, strEmail
  24. strEmail = Request.Form("email")
  25.  
  26. If strEmail = "" Then
  27. oConn.Close
  28. Set objConn = Nothing
  29. Response.Write "<a href='login.html'>"
  30. Response.Write "You must enter a email address"
  31. Response.Write "</a>"
  32. Response.End
  33. End If
  34.  
  35. Set objRS = Server.CreateObject("ADODB.Recordset")
  36. objRS.Open "tblRegister", oConn, , , adCmdTable
  37. bolFound = False
  38.  
  39. Do While Not (objRS.EOF OR bolFound)
  40. If (StrComp(objRS("Email"), strEmail, vbTextCompare) = 0) Then
  41. BolFound = True
  42. Else
  43. objRS.MoveNext
  44. End If
  45. Loop
  46.  
  47. If Not bolFound Then
  48. objRS.Close
  49. Set objRS = Nothing
  50. oConn.Close
  51. Set oConn = Nothing
  52. Response.Write "<a href='login.html'>"
  53. Response.Write "Invalid Email Address.<p>"
  54. Response.Write "</a>"
  55. Response.End
  56. End If
  57.  
  58. If Not (StrComp(objRS("Password"), Request.Form("password"), _
  59. vbBinaryCompare) = 0) Then
  60. objRS.Close
  61. Set objRS = Nothing
  62. oConn.Close
  63. Set oConn = Nothing
  64. Response.Write "<a href='login.html'>"
  65. Response.Write "Invalid password.<p>"
  66. Response.Write "</a>"
  67. Response.End
  68. End If
  69. %>
  70.  
  71. <!-- create form, fill with values from table -->
  72. <form method=post action="modifyuser.asp">
  73. <p>
  74. State: <select name=state type=text value="<%=objRS("State")%>">
  75. <option selected="state">Choose State</option>
  76.     <option value="AL">AL</option>
  77.     <option value="AR">AR</option>
  78.     <option value="AZ">AZ</option>
  79.     <option value="CA">CA</option>
  80.     <option value="CO">CO</option>
  81.     <option value="CT">CT</option>
  82.     <option value="DC">DC</option>
  83. </select>
  84. <p>
  85. <input type=reset> <input type=submit>
  86. </form>
  87. </body>
  88. </html>
  89. <%
  90. objRS.Close
  91. Set objRS = Nothing
  92. oConn.Close
  93. Set oConn = Nothing
  94. %>

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
Nov 4 '08 #1
17 5447
azrar
11
Use javascript at the bottom of your page, something like this:

<script type="text/javascript">
document.form.state.value = "<%=state%>";

//etc..
</script>
Nov 5 '08 #2
jhardman
3,406 Expert 2GB
Jerry,

Azrar's suggestion works (and might be the best approach), but if you want an ASP solution, it would look something like this:
Expand|Select|Wrap|Line Numbers
  1. <select name=state type=text>
  2. <option>Choose State</option>
  3.     <option value="AL"
  4. <% if objRS("state") = "AL" then response.write "SELECTED" %>
  5. >AL</option>
  6.     <option value="AR"
  7. <% if objRS("state") = "AR" then response.write "SELECTED" %>
  8. >AR</option>
  9.     <option value="AZ"
  10. <% if objRS("state") = "AZ" then response.write "SELECTED" %>
  11. >AZ</option>
  12.     <option value="CA"
  13. <% if objRS("state") = "CA" then response.write "SELECTED" %>
  14. >CA</option>
  15.     <option value="CO"
  16. <% if objRS("state") = "CO" then response.write "SELECTED" %>
  17. >CO</option>
  18.     <option value="CT"
  19. <% if objRS("state") = "CT" then response.write "SELECTED" %>
  20. >CT</option>
  21.     <option value="DC"
  22. <% if objRS("state") = "DC" then response.write "SELECTED" %>
  23. >DC</option>
  24. </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
Nov 5 '08 #3
GazMathias
228 Expert 128KB
If your option group comes from a database, then you can do as I usually do:

Expand|Select|Wrap|Line Numbers
  1. <select name="txtState">
  2.     <% Do While Not stateRS.EOF
  3.         If stateRs("statename") = userRS("state") Then %>
  4.             <Option selected><%=stateRs("typename")%></option>
  5.         <% Else %>
  6.             <Option><%=CatRs("statename")%></option>
  7.         <% End If 
  8.     stateRs.MoveNext()
  9.     Loop %>
  10. </select>
  11.  
Gaz
Nov 5 '08 #4
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
Nov 6 '08 #5
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
Nov 6 '08 #6
GazMathias
228 Expert 128KB
Well, Selects have a property called "selected", and check boxes have a similar property called "checked", so therein lies your clue.

Expand|Select|Wrap|Line Numbers
  1. <% If rs("somefield") = true Then %>
  2.     <input type="checkbox" name="chkSubscribed" value="subscribed" checked>
  3. <% Else %>
  4.     <input type="checkbox" name="chkSubscribed" value="subscribed">
  5. <% End If %>

Gaz.
Nov 6 '08 #7
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

Expand|Select|Wrap|Line Numbers
  1. Please check here to opt out of receiving the monthly newsletter:
  2. <% If objRS("nonewsemail") = true Then %>
  3.     <input type="checkbox" name="nonewsemail" value="subscribed" checked />
  4.     <% Else %>
  5.     <input type="checkbox" name="nonewsemail" value="subscribed" />
  6.     <% End If %>Please check here to opt out of receiving the monthly newsletter:
  7. <% If objRS("nonewsemail") = true Then %>
  8.     <input type="checkbox" name="nonewsemail" value="subscribed" checked />
  9.     <% Else %>
  10.     <input type="checkbox" name="nonewsemail" value="subscribed" />
  11.     <% End If %>
Nov 6 '08 #8
GazMathias
228 Expert 128KB
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.
Nov 6 '08 #9
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.

Expand|Select|Wrap|Line Numbers
  1. Please check here to opt out of receiving the monthly newsletter:
  2. <% If objRS("nonewsemail") = true Then %>
  3.     <input type="checkbox" name="nonewsemail" value="" checked>
  4.     <% Else %>
  5.     <input type="checkbox" name="nonewsemail" value="">
  6.     <% End If %>
Nov 7 '08 #10
GazMathias
228 Expert 128KB
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:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Response.Write "<p>Dubug nonewsemail: " & ObjRs("nonewsemail") & "</p>"
  3. %>
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:

Expand|Select|Wrap|Line Numbers
  1. function ChkToBool(value)
  2.         if ucase(value)="ON" then
  3.             ChkToBool=true
  4.         else
  5.             ChkToBool=false
  6.         end if
  7.     end function
Which is then used like, for example:

Expand|Select|Wrap|Line Numbers
  1. rs("SomeField")=ChkToBool(request("SomeCheckBox"))
  2. rs.Update
  3.  
Nov 7 '08 #11
iam_clint
1,208 Expert 1GB
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"
Nov 7 '08 #12
GazMathias
228 Expert 128KB
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.
Nov 7 '08 #13
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

Expand|Select|Wrap|Line Numbers
  1. 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?
Nov 7 '08 #14
GazMathias
228 Expert 128KB
I refer you to my post number 11.
Nov 8 '08 #15
jhardman
3,406 Expert 2GB
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

Expand|Select|Wrap|Line Numbers
  1. 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
Nov 8 '08 #16
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
Nov 9 '08 #17
This post is helpful. I had the same problem and now solved.
Nov 11 '08 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
4
by: Ian Davies | last post by:
Hello I have two drop down menus in my php script. The items displayed in the second is dependent on which item is choosen from the first i.e. the choosen item from the first filters the items in...
1
by: Sakharam Phapale | last post by:
Hi All, How to show dropdown list of menu items just like click on Parent menu. For example, Edit (Parent menu) Cut (child menu) Copy (child menu) Paste (child menu)
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
2
by: Peter | last post by:
ASP.NET 2003 In the DataGrid how do I select current cell value in the dropdown box when I click on the edit link, currently when I click on the edit link in the DataGrid the dropdown box...
6
by: nishac | last post by:
Can anyone suggest me how to make my drop down menu work in IE7 too.Its working in other browsers.On mouse over the submenus should be displayed.Am attaching my css code hereby.Anyone please check...
4
by: Greg Scharlemann | last post by:
I'm trying to setup a dyamic dropdown list that displays a number of text fields based on the selected number in the dropdown. The problem I am running into is capturing the data already entered...
3
by: jerrydigital | last post by:
good evening, I am trying to allow my users to enter in text if they don't find their option on my drop down menu. In the code below, I can get a text box to show up when I select 'Other' on the...
2
coolv
by: coolv | last post by:
Hello I have problem in my page that the dropdown box is not displaying data according to selection of first dropdown.Please help me. Below is my code. thanks.............. <?php ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.