Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reselect multiple list items 1

Status
Not open for further replies.

hererxnl

Technical User
Jul 8, 2003
239
US

This piece will round out server side validation of a user registration. I need to reselect items in a multi select from a form post onload. I have very little experience with javascript arrays and really need some direction.

Here's the select tag and options:
Code:
<select name="days" id="days" size="4" multiple>
  <option>Mon</option>
  <option>Tue</option>
  <option>Wed</option>
  <option>Thu</option>
  <option>Fri</option>
  <option>Sat</option>
  <option>Sun</option>
</select>

Once a user submits their reg form, the server validates the results and redirects back to the reg page if an error has been detected (pretty standard). I'm trying to repopulate their selections to save them time.

I'm able to do this with single selects but the multi is another story. I've got their selections stored in an asp var - strDays.

Any help is greatly appreciated, thanks in advance.


 
You don't need javascript to do this, you should do it in asp. Here's how I'd do it (using server side JScript instead of VBScript, cause I don't know VBScript)
Code:
<%
   //days submitted, stored in an ASP variable
   var a = "Mon|Wed|Fri";
%>
<select name="days" id="days" size="4" multiple>
   <option <%=((a.indexOf("Mon" != -1) ? 'selected="selected"' : '')%>>Mon</option>
   <option <%=((a.indexOf("Tue" != -1) ? 'selected="selected"' : '')%>>Tue</option>
   <option <%=((a.indexOf("Wed" != -1) ? 'selected="selected"' : '')%>>Wed</option>
   .
   .
   .
</select>

-kaht

[small](All puppies have now found loving homes, thanks for all who showed interest)[/small]
 

Thanks again kaht. VBScript is my language, but the approach was dead on.

A star for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top