Solved

Select ALL items on form element list on load

Posted on 2013-12-13
4
325 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 32

Expert Comment

by:Big Monty
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
First on the list didnt work, the last option did, thanks !
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Javascript in a user control not working 17 52
asp syntax 3 20
HTML page and JavaScript 2 49
Hovering effect 9 28
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

772 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

13 Experts available now in Live!

Get 1:1 Help Now