Select Statement help please...

Posted on 2006-10-22
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 51

Accepted Solution

Ryan Chong earned 300 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 100 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.


Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 17

Assisted Solution

gops1 earned 100 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');
                     - 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

733 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