Solved

Select ALL items on form element list on load

Posted on 2013-12-13
4
366 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
[X]
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
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 53

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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
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 viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

707 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