473,666 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

67 New Member
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 5468
azrar
11 New Member
Use javascript at the bottom of your page, something like this:

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

//etc..
</script>
Nov 5 '08 #2
jhardman
3,406 Recognized Expert Specialist
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 Recognized Expert New Member
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
jerrydigital
67 New Member
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
jerrydigital
67 New Member
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 Recognized Expert New Member
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
jerrydigital
67 New Member
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 -"nonewsemai l"- 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 Recognized Expert New Member
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
jerrydigital
67 New Member
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

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

Similar topics

1
2935
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 javascript; I just don't get the syntax at all. If anyone could help, I would appreciate it. I'm probably pretty close. Please note that because it's an Intranet, all users have to use IE 5 or higher. Situation: 3 form fields on an ASP. <select>...
4
1946
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 the second first dropdown menu sub no sub 1 science >>>>>>>>> if this is selected 2 maths 3 something else
1
2135
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
10681
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. Let's say you select 1 of the items, and are properly redirected. You press the back button. I have three servers providing two different functionalities: 1. After pressing the back button, the item you selected in the dropdown is still selected.
2
2846
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 appears in the cell, but allways the first item in the dropdown box is shown not the current cell value? How do I make the current value in the cell automaticaly be selected in the dropdown box.
6
16223
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 and give a positive reply. menu HOme products support..... | | submenus p1 A p2 B.. p3... /*================= STYLES FOR THE PRIMARY NAV...
4
2626
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 before the list is repopulated. For example, suppose the user selects 3 in the drop down list and 3 text fields are shown. If the user populates the 3 text fields with data and decides to change the drop down to a list of 4 or 5, how do I capture...
3
4752
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 drop down menu. However, I cannot get it to work when I try to select 'Other' on the second drop down menu. Any ideas about how I can start getting the second drop down menu to show a text box just like the first one does? Also, how do I get the...
2
2213
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 session_start(); if (!isset($_SESSION)) {
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.