Solved

Select ALL items on form element list on load

Posted on 2013-12-13
4
347 Views
Last Modified: 2013-12-13
I have the following 'list' in my form, I want all items in the list to be selected when the page loads.

<select name="countryDDM" size="5" multiple class="bodytext" id="countryDDM">
     <% 
while (!Country.EOF) {
%>
     <option value="<%=(Country.Fields.Item("country").Value)%>"><%=(Country.Fields.Item("country").Value)%></option>
     <%
  Country.MoveNext();
}
if (Country.CursorType > 0) {
  if (!Country.BOF) Country.MoveFirst();
} else {
  Country.Requery();
}
%>
   </select>

Open in new window



How can I do this ?  

Maybe a javascript ?

I am using classic ASP / javascript
0
Comment
Question by:amucinobluedot
4 Comments
 
LVL 33

Expert Comment

by:Big Monty
ID: 39716935
simple, just apply the "selected" attribute:

<select name="countryDDM" size="5" multiple class="bodytext" id="countryDDM">
     <% 
while (!Country.EOF) {
%>
     <option value="<%=(Country.Fields.Item("country").Value)%> selected="selected""><%=(Country.Fields.Item("country").Value)%></option>
     <%
  Country.MoveNext();
}
if (Country.CursorType > 0) {
  if (!Country.BOF) Country.MoveFirst();
} else {
  Country.Requery();
}
%>
   </select>

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39716947
Use :
<select name="countryDDM" size="5" multiple class="bodytext" id="countryDDM">
     <% 
while (!Country.EOF) {
%>
     <option selected="selected" value="<%=(Country.Fields.Item("country").Value)%>"><%=(Country.Fields.Item("country").Value)%></option>
     <%
  Country.MoveNext();
}
if (Country.CursorType > 0) {
  if (!Country.BOF) Country.MoveFirst();
} else {
  Country.Requery();
}
%>
   </select>

Open in new window

Or just :
<select name="countryDDM" size="5" multiple class="bodytext" id="countryDDM">
     <% 
while (!Country.EOF) {
%>
     <option selected value="<%=(Country.Fields.Item("country").Value)%>"><%=(Country.Fields.Item("country").Value)%></option>
     <%
  Country.MoveNext();
}
if (Country.CursorType > 0) {
  if (!Country.BOF) Country.MoveFirst();
} else {
  Country.Requery();
}
%>
   </select>

Open in new window

0
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39716957
You are mixing up js and asp/vb.  Your serverside code (asp/vb) runs before the page even loads,on the server.  Your js/jquery runs after the page loads, on the client browser.  The two do not meet unless you are using asp's jscript.  Stick with vb for your asp code and js keep at the client level.

You want to end up with
 <select multiple>
  <option value="United States" selected>United States</option>
  <option value="Candada" selected>Canada</option>
  <option value="Mexico" selected>Mexico</option>
  
</select>

Open in new window

 
<select multiple>
<% do until Country.eof%>
  <option value="<%=(Country.Fields.Item("country").Value)%>" selected><%=(Country.Fields.Item("country").Value)%></option>
<%
Country.movenext
loop
%>
  
</select>

Open in new window


It would be faster to use getrows and place the data for your country table in an array but that is for another time.
0
 

Author Closing Comment

by:amucinobluedot
ID: 39716987
First on the list didnt work, the last option did, thanks !
0

Featured Post

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

777 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