Solved

Select Statement help please...

Posted on 2006-10-22
7
1,096 Views
Last Modified: 2012-08-13
HI.

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                                    
</select>
</tr>
<tr>

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
Andy.






0
Comment
Question by:AndyKeen
7 Comments
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 17784270
try this...

<%
   function chkOpt(v1, v2, selectedValue)
         if v1 = v2 then
              chkOpt = selectedValue
       else
              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                              
</select>

?
0
 
LVL 17

Expert Comment

by:gops1
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:

<html>
      <head>
            <title>Select</title>
            <script language="javascript">
                  function dispVal(obj){
                        alert("You have Chosen: "+obj[obj.selectedIndex].value);
                  }
            </script>
      </head>
<body>
<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
      </select>
</form>
</body>
</html>
0
 
LVL 12

Assisted Solution

by:jessegivy
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.

Cheers,

Jesse              
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 17

Assisted Solution

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

<html>
      <head>
            <title>Test Div over Select</title>
                  <style>
                        .ac_menu
                        {
                        border:1px solid black
                        }
                        .ac_normal
                        {
                        background-color:#ffffff;
                        cursor:pointer;
                        }
                  </style>
                  <script language="">
                        function loadFrame(){
                              var DivRef=document.getElementById('ac_menu1');
                              var IfrRef=document.getElementById('DivShim');
                              IfrRef.style.position="absolute";
                              IfrRef.style.width=DivRef.offsetWidth;
                              IfrRef.style.height=DivRef.offsetHeight;
                              IfrRef.style.top=DivRef.style.top;
                              IfrRef.style.left=DivRef.style.left;
                              IfrRef.style.zIndex=DivRef.style.zIndex - 1;
                              IfrRef.style.display="";
                        }
            </script>
      </head>
<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">
            simple
            </div>
            <div class="ac_normal">
            simple text
            </div>
            <div class="ac_normal">
            simple text to
            </div>
            <div class="ac_normal">
            simple text to cover a
            </div>
            <div class="ac_normal">
            simple text to cover a select
            </div>
            <div class="ac_normal">
            simple text to cover a select box
            </div>
      </div>
      <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>
      </select>
</body>
</html>
0
 
LVL 1

Author Comment

by:AndyKeen
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.
Andy
0
 
LVL 17

Expert Comment

by:gops1
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.
0
 
LVL 1

Author Comment

by:AndyKeen
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.

Regards
Andy.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
compact pure CSS Read More Toggle 4 69
execute script based on HTML event 7 24
Browser Chrome downloads colored link 5 41
Create animated movies for web page 18 46
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
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…

803 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