View Full Version : Drop downs on edit page.

10-21-2003, 06:38 PM
I have some drop downs on my edit page. I would like to have the current value comming from the database displayed and change it with the dropdown if needed. I have it working but if I make no changes, the fields get updated to null.
Any help would be great.

eRs is the one row record that's being editted.
Rs is the recordset that holds the list of names.

<table name=resources align=left cellpadding=0 border=0 width=540 style="position:relative; left:0; top:0" bgcolor=DeepSkyBlue>

<tr><td><font size=4 color=Black>Resources</td></tr>

<tr><td align=right>Business Analyst:</td><td>
<Select Name=EmpDropDwn1 align=left><%
Response.Write("<option value=>"&eRs("ANALYST"))
do while Rs.EOF=false
Response.Write("<option value='"&Rs("emp")&"'>")
Response.Write server.HTMLEncodeRs.Fields"emp")) "</option>")

10-21-2003, 11:17 PM
Is this supposed to be the current value ?

Response.Write("<option value=>"&eRs("ANALYST"))

Because it has no value. Only a lable.

10-21-2003, 11:21 PM
You are correct as usual. I fugured it out by looking at the source when I ran the page. Here is the code I came up with and it works.

Thanks for your help!

Response.Write("<option value='"&eRs("ANALYST")&"'>")
Response.Write eRs("ANALYST")& "</option>"

do while Rs.EOF=false

Response.Write("<option value='"&Rs("emp")&"'>")
Response.Write(server.HTMLEncode(Rs.Fields("emp")) & "</option>")


10-22-2003, 12:05 AM
Just a small remark : try to make your output xhtml-valid, and use " instead of ' for atributevalues. Like

Response.Write("<option value=""" & eRs("ANALYST") & """>" & eRs("ANALYST") & "</option>"

do while Rs.EOF=false
Response.Write("<option value=""" & Rs("emp")&""">" & server.HTMLEncode(Rs.Fields("emp")) & "</option>")

Also, now you have the current value at the top. But it will probably appear double. It's nicer to just have it once, and in the right sequence (so not the current at the top and then the sequence. Like

do while Rs.EOF=false
Response.Write("<option value=""" & Rs("emp")&"""")
if Rs("emp") = eRs("ANALYST") then
response.write(" selected=""selected""")
end if
response.write(">" & server.HTMLEncode(Rs.Fields("emp")) & "</option>")

(it's also better to use Rs.Fields("emp").Value instead of Rs("emp"), and if its a rather large recordset, to store the recordset in an array, using GetRows --> run a search here for more info)

10-22-2003, 05:42 AM
raf, I'm trying to get my fellow developers to write XHTML valid code, as well.

My arguments are:

1. It's the most up-to-date HTML
2. It's backwards compatible, and forwards compatible!
3. It is MUCH cleaner code
4. Less problems with syntax errors, etc.
5. It's a STANDARD! Standards are GOOD! I think that's the main point... developers need to realize we're on the same team and we should be coding to the same standard, so we're all on the same page...

Some of them are like "Why should I learn that? The code I've been writing for five years still works" ...which isn't always true, and I've pointed that out every time I've had to help them fix it - but I can see their point as well at times, even though I HATE to write sloppy code.

Example of some of the stuff I have to deal with (not the worst, and not the best, but an example):

<font face = arial +2><b><input type = text name = example value = "hi there"></b></font>


No quotes around attributes, spaces which shouldn't be there (which by the way screws up the current implementation of Mozilla, at the least!), font tags everywhere, unclosed tags, etc. ...and don't even ask what that "+2" is supposed to be, although I think it was an attempt someone made at font sizing?

I've got a few links that suggest reasons why people should write compliant code, and I think I've started to convince a few of them, but I was wondering if you had any additional input on this subject.

Personally I think just the modular aspect (i.e. stylesheets, no ugly font tags, external (and cached!) scripts) is enough it itself, not to mention browser compatibility, etc.... the only challenge is convincing other people to start writing clean (and standards compliant) code. :|

I've helped all of them figure out solutions enough that they're starting to see my point (and when sloppy or non-compliant code is the problem I make sure I point it out!), but any further nudges in this direction would be helpful. :D

10-22-2003, 10:23 AM
Well, I never understand why people don't simply agree with standard-compliane. I think it's just the only sensible thing to do.

- if you write valid HTML, then writing valid XHTML is like reading one or two pages of changes
- the number of canvasses is growing each year. cellphones, pocket pc's, palms, ... If you want to send content to those with an accaptable layout, then you need to use valid XHTML and CSS. And in the future, we're surely gonna be writing XML and XSL. So why not grow into that now?
- every party needs to play it's role. Codegenerators and developpers need to produce valid code, browser-builders need to produce standard-compliant browsers (start working, Gates), users should only use standard compliant browsers.
- if you care about your users, then you want to enable them to 'read' your site. And this also goes for (visually) inpaired users. If there werent standards, then it would be impossible to create screenreaders etc. So start writing valid code so that screenreaders can correctly process your code.
- one of the current evolutions are databrokering and integrating of 'independ' application. They need to speak the same language. Standards need to be set and followed to allow optimal use of content and to be able to apply your own look and feel to other peoples content
- if everyone follows W3C-standards, then this will make development cheaper

10-22-2003, 04:14 PM
Thank you raf for the elegent code. Thanks both of you for the advice on xhtml. I will start using it today. My background is Oracle development and I have only been working with ASP, javascript and HTML for a few months, so I am very green. Often I am just trying to get things to work because my employer has not sponsered any formal training. Everthing I know I get from here, w3schools and devguru, so I really appreciate the input.
I am always trying to get new developers to write their SQL and PL/SQL to standards and it's sometimes lie pulling teeth.

Thanks again!!!

10-22-2003, 04:41 PM
Actually w3schools is a great place to learn XHTML. :)

10-22-2003, 05:05 PM
I was wondering if there is a way that the user could start typing the analyst name in the dropdown and have the name pop in if it's in the recordset and if not add the name to the database?

10-22-2003, 06:54 PM
Yes. Very well possible, but this will probably be done in javascript (which i don't know well + which i try to avoid.)

I've seen some threads about this lookup function so if you run a search here ...

But i would just stick with the dropdown. If the list isn't to long, it's not a real problem for the users to run through it. If it's rather long, then i would cut it up and let the user select the first letter. (by displayng the letters fro a to z as links with that letter in the querystring)
Processing large recordsets and sending the complete list to the browser will take up to much resources.

Roy Sinclair
10-22-2003, 11:00 PM
Originally posted by elcaro2k
I was wondering if there is a way that the user could start typing the analyst name in the dropdown and have the name pop in if it's in the recordset and if not add the name to the database?

See this thread: http://www.codingforums.com/showthread.php?s=&threadid=9865