Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Select Statement help please...

Posted on 2006-10-22
Medium Priority
Last Modified: 2012-08-13

OK - I am not an HTML programmer - I am a VB Programmer and I understand HTML and this is our first venture into ASP with HTML - and I'm stuck.

The Problem.
We have designed a web site for a heavy plant machinery customer where by they can advertise for sale pieces of plant.

The web site, which we have adopted from another web site allows the user to upload a photo and add description price etc etc.

The problem is when they come to edit an entry. We have added a select statement that allows them to choose from a specific list of equipment type and for a new entry this works fine, but when they edit the item the same select list is used but it defaults to the first item in the select list.

What we require is the field to display the current selection that has been saved in the access database - with also the ability to use the drop down list and select a different model type if required.

Our standard field code looks like this:
<input name="Price" size="40" value="<%=rs("Price")%>"></font></td>                   - "Price" being the stored value from the database.

Our Select Statement looks like this:
<select name="Type" size="1" value="<%=rs("Type")%>">
 <option VALUE="BackHoe/Loaders">BackHoe/Loaders
 <option VALUE="Breakers">Breakers
 <option VALUE="Compressors">Compressors
 <option VALUE="Dumpers">Dumpers
 <option VALUE="Excavators">Excavators
<option VALUE="Misc">Miscellaneous
<option VALUE="Mixers">Mixers
<option VALUE="Rollers-Tandem/Pedestrian">Rollers-Tandem/Pedestrian
<option VALUE="Skid Steel Loaders">SkidSteelLoaders
<option VALUE="Telescopic Handlers/Forklifts">Telescopic Handlers/Forklifts                                    

However the above code section - value="<%=rs("Type")%>"> does not display the stored database value - instead is SHOWS (But has not been stored yet) the first int he select list - "BackHoe/Loaders"

Could anyone provide me with the actual code I need.

Many thanks

Question by:AndyKeen
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 53

Accepted Solution

Ryan Chong earned 1200 total points
ID: 17784270
try this...

   function chkOpt(v1, v2, selectedValue)
         if v1 = v2 then
              chkOpt = selectedValue
              chkOpt = ""
        end if
  end function


<select name="Type" size="1">
 <option VALUE="BackHoe/Loaders" <%=chkOpt("BackHoe/Loaders","" & rs("Type"), " selected")%>>BackHoe/Loaders
 <option VALUE="Breakers" <%=chkOpt("Breakers","" & rs("Type"), " selected")%>>Breakers
 <option VALUE="Compressors" <%=chkOpt("Compressors","" & rs("Type"), " selected")%>>Compressors
 <option VALUE="Dumpers" <%=chkOpt("Dumpers","" & rs("Type"), " selected")%>>Dumpers


<option VALUE="Telescopic Handlers/Forklifts" <%=chkOpt("Telescopic Handlers/Forklifts","" & rs("Type"), " selected")%>>Telescopic Handlers/Forklifts                              

LVL 17

Expert Comment

ID: 17784590
for the <select> tag we do not have to have the "value" attribute, instead it should be for the <option> tag:

Here is one sample HTML which you can try it out:

            <script language="javascript">
                  function dispVal(obj){
                        alert("You have Chosen: "+obj[obj.selectedIndex].value);
<form name="testSelect">
      <select name="test" onchange="javascript:dispVal(this)">
            <option value="No Value" selected>-- Select --
            <option value="First Value">Value 1
            <option value="Second Value">Value 2
            <option value="Third Value">Value 3
            <option value="Fourth Value">Value 4
LVL 12

Assisted Solution

jessegivy earned 400 total points
ID: 17785905
...please close option tags :)

 <option VALUE="BackHoe/Loaders">BackHoe/Loaders</option>
 <option VALUE="Breakers">Breakers</option>
 <option VALUE="Compressors">Compressors</option>
 <option VALUE="Dumpers">Dumpers</option>
 <option VALUE="Excavators">Excavators</option>
<option VALUE="Misc">Miscellaneous</option>
<option VALUE="Mixers">Mixers</option>
<option VALUE="Rollers-Tandem/Pedestrian">Rollers-Tandem/Pedestrian</option>
<option VALUE="Skid Steel Loaders">SkidSteelLoaders</option>
<option VALUE="Telescopic Handlers/Forklifts">Telescopic Handlers/Forklifts</option>

...humor me about the ASP (it's been a while).  I assume that rs represents a single record from the database?  If not won't you need to iterate through many records to retrieve the data?

...any way.  Typically I believe what you're looking fro is to have a code render block within the select tag that fills the value and text for each option tag.  This would be accomplished with a loop, typically you'll use the primary key of the lookup table as the value.  Makes for quicker processing once you submit.


Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 17

Assisted Solution

gops1 earned 400 total points
ID: 17786667
Andy there is a small change. Ignore the previous and try out this code:

            <title>Test Div over Select</title>
                        border:1px solid black
                  <script language="">
                        function loadFrame(){
                              var DivRef=document.getElementById('ac_menu1');
                              var IfrRef=document.getElementById('DivShim');
                              IfrRef.style.zIndex=DivRef.style.zIndex - 1;
<body onload="loadFrame();">
      <iframe id="DivShim" style="display:none;position: absolute;" frameborder="0" border="0"></iframe>
      <div id="ac_menu1" class="ac_menu" style="visibility: visible; position: absolute; z-index: 100; ">
            <div class="ac_normal">
            <div class="ac_normal">
            simple text
            <div class="ac_normal">
            simple text to
            <div class="ac_normal">
            simple text to cover a
            <div class="ac_normal">
            simple text to cover a select
            <div class="ac_normal">
            simple text to cover a select box
      <select id="testSelect" size="5" multiple="yes">
            <option value="1">test 1</option>
            <option value="2">test 2</option>
            <option value="3">test 3</option>
            <option value="4">test 4</option>
            <option value="5">test 5</option>

Author Comment

ID: 17787079
Hi Folks.

Thanks for all your help.

The problem has been sorted and I will accept RYANCYS answer. My personal opinion is that Ryan's answer was the simplest and I understood it more because it looked more like a VB function - implementation worked the first time and seem's the cleanest - that said I would like to split the points between you all with most going to Ryan. I am concious that people take the time to help each other and I think that in itself deserves a reward.

Thank you all.
LVL 17

Expert Comment

ID: 17787153
Andy actually my second was a wrong post, it was entirely for a different query. Sorry for this but my first post was entirely for you and it is a valid one.

Author Comment

ID: 17787163
Hi Gops1.

Thanks for that - I have to admit I looked at it and I thought. rriiiggghhhhtttttttt..... what the hecks that all about........ way over my head....

Thanks for the info - I have accepted an answer and split the points (see above) - thanks for the input - much appreciated.


Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Find out what you should include to make the best professional email signature for your organization.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

597 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question