una soluzione
codice:
<%@ language="VBScript" %>
<%
option explicit
Response.Buffer = true
dim p_select1, p_select2
onLoad
sub onLoad()
p_select1 = trim(Request.Form("p_select1"))
p_select2 = Split(trim(Request.Form("p_select2")), ",")
end sub
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Pagina senza titolo</title>
</head>
<body>
<form id="form1" method="post" action="?">
<label for="select1">
Listbox selezione semplice</label>
<select size="4" id="select1" name="p_select1">
<option value='1' <%=selected(p_select1, "1")%>>Stefano</option>
<option value="2" <%=selected(p_select1, "2")%>>Carlo</option>
<option value="3" <%=selected(p_select1, "3")%>>Nicola</option>
</select>
<hr/>
<label for="select2">
Listbox selezione multipla</label>
<select size="4" id="select2" name="p_select2" multiple="multiple">
<option value="1" <%=trovato(p_select2, "1")%>>Stefano</option>
<option value="2" <%=trovato(p_select2, "2")%>>Carlo</option>
<option value="3" <%=trovato(p_select2, "3")%>>Nicola</option>
</select>
<input id="Submit1" type="submit" value="submit" />
p_select1 = <%=trim(Request.Form("p_select1")) %></p>
p_select2 = <%=trim(Request.Form("p_select2")) %></p>
</form>
</body>
</html>
<script runat="server" language="vbscript">
'--------------------------------------------------------------
'ristabilisce la selezione in una opzione di una select
'--------------------------------------------------------------
function selected(firstVal, secondVal)
if cstr(firstVal) = cstr(secondVal) then
Selected = " SELECTED "
else
Selected = ""
end if
end function
'--------------------------------------------------------------
'ristabilisce la selezione in un checkbox
'--------------------------------------------------------------
function checked(firstVal, secondVal)
if cstr(firstVal) = cstr(secondVal) then
checked = " CHECKED "
else
checked = ""
end if
end function
'--------------------------------------------------------------
'ristabilisce la selezione in un checkbox
'firstVal è una stringa che contiene una o più chiavi da
'confrontare con secondVal
'--------------------------------------------------------------
function checked_array(firstVal, byval secondVal)
dim a, tmp
if firstVal = "" then
checked_array = ""
exit function
end if
a = split(firstVal, ",")
for each tmp in a
tmp = ucase(trim(tmp))
secondVal = ucase(trim(secondVal))
if tmp = secondVal then
checked_array = " CHECKED "
exit function
end if
next
checked_array = ""
end function
'--------------------------------------------------------------
'ristabisce la selezione di più righe in un selectbox
'--------------------------------------------------------------
function Trovato(MyArray, findVal)
Dim bTrovato
Dim MyIndex
dim i
for i = lbound(MyArray) to ubound(MyArray)
if ucase(trim(MyArray(i))) = ucase(trim(cstr(findVal))) then
Trovato = " SELECTED "
exit function
end if
next
Trovato = ""
end function
</script>