Solved

Select ALL items on form element list on load

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
migrating to phpbb forum from vBulletin 4.2 3 23
Tools for analysis of code 4 44
Triple line in an alert message 4 19
Print a <div></div> only 5 33
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

713 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