|
-
Jul 4th, 2001, 10:02 AM
#1
Thread Starter
Addicted Member
Easy question : SELECT and multiple selections
Hi,
I'm using a select to display the result of a search. Now the user can select multiple rows and I'm opening a new page containing only those records.
What I want to know is how to determine which rows are selected since mydoc.myform.mylist.selectedindex only returns the index of the last selected item, same for value.
-
Jul 4th, 2001, 10:55 AM
#2
Fanatic Member
To get multiple values you have to loop through the options[] array and check the SELECTED property.
<html>
<head>
<title></title>
<script LANGUAGE = "JavaScript">
var buttonClicked = false;
function getRows(){
var intIndex;
for(intIndex = 0;intIndex < frmMain.sctNames.length;intIndex++){
if(frmMain.sctNames.options[intIndex].selected){
frmMain.txtResult.value += frmMain.sctNames.options[intIndex].index;
alert(frmMain.sctNames.options[intIndex].index);
}//end if
}//end for
}//end function
</script>
</head>
<body>
<form NAME = "frmMain">
<select NAME = "sctNames" MULTIPLE>
<option>Harry Henderson</option>
<option>John LeClair</option>
<option>Mario Lemieux</option>
<option>Jeremy Roenick</option>
</select>
<br>
<input TYPE = "text" NAME = "txtResult">
<br>
<input TYPE = "button" VALUE = "Get Rows" ONCLICK = "getRows();">
</form>
</body>
</html>
Chris
-
Jul 4th, 2001, 12:23 PM
#3
Thread Starter
Addicted Member
Ok, thanks for the reply Psyrus !
I tried your idea, but my Vbscript code doesn't work
Any idea wh'ats wrong with it ?
Code:
Sub AddElem()
Dim i
Dim strRecherche
With document.frmRechercher
For i = 1 to <%= rs.RecordCount %>
If .lstRechercher.options(i).selected Then
strRecherche = strRecherche & .lstRechercher.options(i).value & "*!*"
End if
Next
End With
msgbox strRecherche
End Sub
-
Jul 4th, 2001, 02:25 PM
#4
Fanatic Member
The array starts at 0 index so start your loop there. I think you have to change it to options[], maybe not in VBScript though.
Chris
-
Jul 4th, 2001, 02:58 PM
#5
Thread Starter
Addicted Member
That did the trick !
Thanks a lot again !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|