[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Select ALL items on form element list on load

Posted on 2013-12-13
4
Medium Priority
?
374 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 2000 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 54

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 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