Solved

Select Statement help please...

Posted on 2006-10-22
7
1,091 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 49

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now