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
17 5468
Use javascript at the bottom of your page, something like this:
<script type="text/javascript">
document.form.s tate.value = "<%=state%> ";
//etc..
</script>
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: - <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
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
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
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
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.
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 - 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 %>
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.
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 %>
Sign in to post your reply or Sign up for a free account.
Similar topics |
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>...
|
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
|
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)
|
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.
|
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.
| |
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...
|
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...
|
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...
|
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)) {
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |