PDA

View Full Version : how to make 2 multiple select boxes in between?


NinjaTurtle
12-03-2002, 11:22 AM
dear,

how to make 2 multiple select boxes in between?

example,
left hand side is a Student list, right is Selected course student list, how to select user to right hand site from left hand side using
double click ? and how to list them in the page with ASP.

this is an example:

<form>
<table width="90%">
<tr class="browtitleTD">
<td width="46%" class="verdanabbodytext"><div align="center">Student list</div></td>
<td width="6%">&nbsp;</td>
<td width="48%" class="verdanabbodytext"><div align="center">Computer Student list</div></td>
</tr> <tr>
<td width="45%"> <div align="center">
<select multiple size="10" name="list1" style="width:150px">
<option value="11"> 1.1 </option>
<option value="12"> 1.2 </option>

</select>
</div></td>
<td width="10%">
<div align="center">
<input type="button" value=" &gt;&gt; " onclick="move(this.form.list1,this.form.list2)" name="B1">
<BR>
<input type="button" value=" &lt;&lt; " onclick="move(this.form.list2,this.form.list1)" name="B2">
</div></td>
<td width="45%"> <div align="center">
<select multiple size="10" name="list2" style="width:150px">
</select>
</div></td></tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td></tr>
</table>
</form>

glenngv
12-03-2002, 11:57 AM
<select multiple size="10" name="list1" style="width:150px" ondblclick="move(this.form.list1,this.form.list2)">
<option value="11"> 1.1 </option>
<option value="12"> 1.2 </option>
</select>

<select multiple size="10" name="list2" style="width:150px" ondblclick="move(this.form.list2,this.form.list1)">
</select>


take note that the user has to press SHIFT key while double-clicking multiple selected items so as not to remove the selection to other items.
So you should have a small note instructing user about this.

NinjaTurtle
12-05-2002, 03:22 AM
how to remain the records that already choose to the left hand site list box when i refresh(document.form.submit()) the page?
i do thata bcos i can allow user choose different users from drop down list. then they can choose from diifrent department users.

glenngv
12-05-2002, 03:35 AM
post the whole code pls

NinjaTurtle
12-05-2002, 07:01 AM
<html>
<head>
<title><title>
<link href='../../intranet.css' rel='stylesheet' type='text/css'>
<Script language="JavaScript" src="../dragNdrop.js"></Script>
</head>
<%
dim Sorting,usergroup,TempSysUser
Sorting = request.QueryString("sortby")
usergroup = request.QueryString("usergroup")
TempSysUser = request.QueryString("list2")
response.write TempSysUser
dim connPro, rsPro, strOption, strSQL, rssystemcode,rssystemdesc
strSQL = "SELECT * FROM tbSystemname where fcompanycode='"&Session("CompanyCode")&"' and fupdstat='A' order by fsystemcode"
set rsPro = server.createObject("ADODB.Recordset")
rsPro.Open strSQL, int_databasepath
strOption = ""
If not rsPro.EOF and not rsPro.BOF then
Do Until rsPro.EOF
rssystemcode = trim(rsPro("fsystemcode"))
rssystemdesc = trim(rsPro("fsystemdesc"))
strOption = strOption & _
"<option value='"&rssystemcode&"$#"&rssystemdesc&"'>"&rssystemdesc&"</option>"&vbcrlf
rsPro.movenext
Loop
else
strOption = "<option value=''>No Record Found.</option>"
end if
rsPro.Close
set rspro = nothing
set connPro = nothing

dim connUser, rsUser, strOptionUser, rsfid,rsfname,rsfgroup
if (Sorting="" OR Sorting="n" OR Sorting="a") then
strSQL = "SELECT * FROM Sysuser where faccountstatus='a' order by fname, fgroup "
elseif Sorting="c" then
strSQL = "SELECT * FROM Sysuser where faccountstatus='a' order by fgroup,fname "
elseif (Sorting<>"" AND Sorting<>"n" AND Sorting="a" AND Sorting="c" AND Sorting<>"cc") then
strSQL = "SELECT * FROM Sysuser"' where fgroup='"&Sorting&"' and faccountstatus='a' order by fname, fgroup "
else
strSQL = "SELECT * FROM Sysuser where fgroup='"&trim(usergroup)&"'"' and faccountstatus='a' order by fname, fgroup "
end if
set rsUser = server.createObject("ADODB.Recordset")
rsUser.Open strSQL, int_databasepath
strOptionUser = ""
If not rsUser.EOF and not rsUser.BOF then
Do Until rsUser.EOF
rsfid = trim(rsUser("fid"))
rsfname = trim(rsUser("fname"))
rsfgroup = trim(rsUser("fgroup"))
strOptionUser = strOptionUser & _
"<option value='"&rsfid&"'>"&rsfname& " ("&rsfgroup&")</option>"&vbcrlf
rsUser.movenext
Loop
else
strOptionUser = "<option value=''>No Record Found.</option>"
end if
rsUser.Close
set rsUser = nothing
set connUser = nothing

dim connCom, rsCom, strOptionCom, rsgroup
strSQL = "SELECT DISTINCT(fgroup) FROM Sysuser order by Fgroup"
set rsCom = server.createObject("ADODB.Recordset")
rsCom.Open strSQL, int_databasepath
strOptionCom = ""
If not rsCom.EOF and not rsCom.BOF then
Do Until rsCom.EOF
rsgroup = trim(rsCom("fgroup"))
'rsCompanyname = trim(rsCom("fdesc"))
strOptionCom = strOptionCom & _
"<option value='"&rsgroup&"'>"&rsgroup& "</option>"&vbcrlf
rsCom.movenext
Loop
else
strOptionCom = "<option value=''>No Record Found.</option>"
end if
rsCom.Close
set rsCom = nothing
set connCom = nothing
%>
<body>
<center>
<table width="100%" border="0" align="center" cellspacing="0">
<tr>
<td width="70%" class="Verdanatitle">System Access<br> <br> </td>
<td align="right" width="30%" class="Verdanatext">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="Verdanatitle"> <table width="85%" border="0" align="center" class="tabletitle">
<tr>
<td width="21%" class="subtitleTD">System Name</td>
<td width="79%" class="bbodyTD"><select name="select" class="txtbox">
<option selected>-- Select a system --</option>
<%=strOption%> </select></td>
</tr>
<tr>
<td valign="top" class="subtitleTD">Select User</td>
<td class="bbodyTD">
<form name="form1">
<table width="90%">
<tr class="browtitleTD">
<td width="37%" colspan="2" class="verdanabbodytext"><div align="center">Company
Staff</div></td>
<td width="8%">&nbsp;</td>
<td width="46%" class="verdanabbodytext"><div align="center">System
User</div></td>
</tr>
<tr>
<td colspan="2"> <div align="left">
<select multiple size="10" name="list1" style="width:280px" ondblclick="move(document.form1.list1,document.form1.list2)">
<%=strOptionUser%>
</select>
</div></td>
<td width="8%"> <div align="center">
<input name="B1" type="button" class="Smallbutton" onclick="move(document.form1.list1,document.form1.list2)" value=" &gt;&gt; ">
<BR>
<input name="B2" type="button" class="Smallbutton" onclick="move(document.form1.list2,document.form1.list1)" value=" &lt;&lt; "><BR><BR>
</div></td>
<td width="46%"> <div align="center">
<select multiple size="10" name="list2" style="width:280px" ondblclick="move(document.form1.list2,document.form1.list1)">
<%=TempSysUser%>
</select>
</div></td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall">&nbsp;</td>
</tr>
<tr>
<td class="verdanasmall"><span class="verdanasmall">Sort by:</span></td>
<td colspan="3" class="verdanasmall"><input type="radio" name="sortby" value="cc">
Selected user group: <select name="usergroup" class="txtbox" onChange="document.form1.sortby[0].checked=true;document.form1.submit()">
<option value="0" selected>-- Select user group --</option>
<%=strOptionCom%> </select> </td>
</tr>
<tr>
<td width="9%" class="verdanasmall"><br> </td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="c" onclick="document.form1.submit()">
User group</td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="n" onclick="document.form1.submit()">
Name</td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="a" onclick="document.form1.submit()">
All</td>
</tr>
</table>
</form></td>
</tr>
</table></td>
</tr>
</table>
<br>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletitle">
<tr>
<td height="21">
<div align="center">
<input name="Submit3" type="submit" class="Submitbutton" value="Submit">
&nbsp;
<input name="Submit4" type="reset" class="Submitbutton" value="Reset">
</div></td>
</tr>
</table>
<br>
</center>


<center>
<!-- #INCLUDE FILE="../Sharebutton.asp"-->
</center>
</body>
</html>

glenngv
12-05-2002, 07:57 AM
add this vbscript code:

<%
dim strOptionSelectedUsers
TempSysUser = request.QueryString("list2")
response.write "list2 items: " & TempSysUser & "<br>"
arrSelectedUsers = split(TempSysUser)
response.write "Ubound: " & ubound(arrSelectedUsers) & "<br>"
if ubound(arrSelectedUsers)>-1 then 'then it is a "valid" array
for each item in arrSelectedUsers
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & item & """>" & item & "</option>" & VbCrLf
next
end if
%>


then insert the asp variable inside the list2 select tag:
...
<select multiple size="10" name="list2" style="width:280px" ondblclick="move(document.form1.list2,document.form1.list1)">
<%=strOptionSelectedUsers%>
</select>
...

then in ALL onclicks in your form controls that call document.form1.submit(), change each of them like this:

<input type="radio" name="sortby" value="c" onclick="doSubmit(this.form)">

then create the doSubmit() function:

<script type="text/javascript">
//this function selects all items in list2 combo so that each item is submitted to the server
function doSubmit(f){
for (var i=0;i<f.list2.options.length;i++){
f.list2.options[i].selected = true;
}
f.submit();
}
</script>


I noticed that you use GET method in your form. If method is not supplied, GET is the default. It means that all data are appended in the URL once the page is submitted. I suggest you use the POST method and change all Request.QueryString to Request.Form.
I also noticed that there is a select tag named "select" that is outside the form tag. If a control is outside the form tag, it will not display in the page especially in Netscape, though IE is forgiving on this. It's always a good habit to put all html controls inside the form tag.

NinjaTurtle
12-10-2002, 02:45 AM
This is the new Source code:

<html>
<head>
<title></title>
<Script language="JavaScript" src="../dragNdrop.js"></Script>
<Script language="JavaScript">
function doSubmit(f){
for (var i=0;i<f.list2.options.length;i++){
f.list2.options[i].selected = true;
}
f.submit();
}
</Script>
</head>
<%
dim Sorting,usergroup,TempSysUser
Sorting = request.QueryString("sortby")
usergroup = request.QueryString("usergroup")
TempSysUser = request.QueryString("list2")
dim connPro, rsPro, strOption, strSQL, rssystemcode,rssystemdesc
strSQL = "SELECT * FROM tbSystemname where fcompanycode='"&Session("CompanyCode")&"' and fupdstat='A' order by fsystemcode"
set rsPro = server.createObject("ADODB.Recordset")
rsPro.Open strSQL, int_databasepath
strOption = ""
If not rsPro.EOF and not rsPro.BOF then
Do Until rsPro.EOF
rssystemcode = trim(rsPro("fsystemcode"))
rssystemdesc = trim(rsPro("fsystemdesc"))
strOption = strOption & _
"<option value='"&rssystemcode&"$#"&rssystemdesc&"'>"&rssystemdesc&"</option>"&vbcrlf
rsPro.movenext
Loop
else
strOption = "<option value=''>No Record Found.</option>"
end if
rsPro.Close
set rspro = nothing
set connPro = nothing

dim connUser, rsUser, strOptionUser, rsfid,rsfname,rsfgroup
if (Sorting="" OR Sorting="n" OR Sorting="a") then
strSQL = "SELECT * FROM Sysuser where faccountstatus='a' order by fname, fgroup "
elseif Sorting="c" then
strSQL = "SELECT * FROM Sysuser where faccountstatus='a' order by fgroup,fname "
elseif (Sorting<>"" AND Sorting<>"n" AND Sorting="a" AND Sorting="c" AND Sorting<>"cc") then
strSQL = "SELECT * FROM Sysuser"' where fgroup='"&Sorting&"' and faccountstatus='a' order by fname, fgroup "
else
strSQL = "SELECT * FROM Sysuser where fgroup='"&trim(usergroup)&"'"' and faccountstatus='a' order by fname, fgroup "
end if
set rsUser = server.createObject("ADODB.Recordset")
rsUser.Open strSQL, int_databasepath
strOptionUser = ""
If not rsUser.EOF and not rsUser.BOF then
Do Until rsUser.EOF
rsfid = trim(rsUser("fid"))
rsfname = trim(rsUser("fname"))
rsfgroup = trim(rsUser("fgroup"))
strOptionUser = strOptionUser & _
"<option value='"&rsfid&"$#"&rsfname&"'>"&rsfname& " ("&rsfgroup&")</option>"&vbcrlf
rsUser.movenext
Loop
else
strOptionUser = "<option value=''>No Record Found.</option>"
end if
rsUser.Close
set rsUser = nothing
set connUser = nothing

dim connCom, rsCom, strOptionCom, rsgroup
strSQL = "SELECT DISTINCT(fgroup) FROM Sysuser order by Fgroup"
set rsCom = server.createObject("ADODB.Recordset")
rsCom.Open strSQL, int_databasepath
strOptionCom = ""
If not rsCom.EOF and not rsCom.BOF then
Do Until rsCom.EOF
rsgroup = trim(rsCom("fgroup"))
'rsCompanyname = trim(rsCom("fdesc"))
strOptionCom = strOptionCom & _
"<option value='"&rsgroup&"'>"&rsgroup& "</option>"&vbcrlf
rsCom.movenext
Loop
else
strOptionCom = "<option value=''>No Record Found.</option>"
end if
rsCom.Close
set rsCom = nothing
set connCom = nothing
%>
<body>
<%
dim strOptionSelectedUsers,arrSelectedUsers,i,item,j
TempSysUser = request.QueryString("list2")
arrSelectedUsers = split(TempSysUser,",")
response.write "list2 items: " & ubound(arrSelectedUsers) & "<br>"
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
response.write i & ": " & arrSelectedUsers(i) & "<br>"
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & arrSelectedUsers(i)& """>" & arrSelectedUsers(i) & "</option>" & VbCrLf
SplitID = split(arrSelectedUsers(i),"$#")
for j = 0 to ubound(SplitID)
response.write "j: " & SplitID(1) & "<br>"
next
'SplitID(i) & "</option>" & VbCrLf

next
%>

<center>
<form name="form1">
<table width="100%" border="0" align="center" cellspacing="0">
<tr>
<td width="70%" class="Verdanatitle">System Access<br> <br> </td>
<td align="right" width="30%" class="Verdanatext">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="Verdanatitle"> <table width="85%" border="0" align="center" class="tabletitle">
<tr>
<td width="21%" class="subtitleTD">System Name</td>
<td width="79%" class="bbodyTD"><select name="select" class="txtbox">
<option selected>-- Select a system --</option>
<%=strOption%> </select></td>
</tr>
<tr>
<td valign="top" class="subtitleTD">Select User</td>
<td class="bbodyTD">

<table width="90%">
<tr class="browtitleTD">
<td width="37%" colspan="2" class="verdanabbodytext"><div align="center">Company
Staff</div></td>
<td width="8%">&nbsp;</td>
<td width="46%" class="verdanabbodytext"><div align="center">System
User</div></td>
</tr>
<tr>
<td colspan="2"> <div align="left">
<select multiple size="10" name="list1" style="width:280px" ondblclick="move(document.form1.list1,document.form1.list2)">
<%=strOptionUser%>
</select>
</div></td>
<td width="8%"> <div align="center">
<input name="B1" type="button" class="Smallbutton" onclick="move(document.form1.list1,document.form1.list2)" value=" &gt;&gt; ">
<BR>
<input name="B2" type="button" class="Smallbutton" onclick="move(document.form1.list2,document.form1.list1)" value=" &lt;&lt; "><BR><BR>
</div></td>
<td width="46%"> <div align="center">
<select multiple size="10" name="list2" style="width:280px" ondblclick="move(document.form1.list2,document.form1.list1)">

<%=strOptionSelectedUsers%>
</select>
</div></td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall">&nbsp;</td>
</tr>
<tr>
<td class="verdanasmall"><span class="verdanasmall">Sort by:</span></td>
<td colspan="3" class="verdanasmall"><input type="radio" name="sortby" value="cc">
Selected user group: <select name="usergroup" class="txtbox" onChange="document.form1.sortby[0].checked=true;document.form1.submit()">
<option value="0" selected>-- Select user group --</option>
<%=strOptionCom%> </select> </td>
</tr>
<tr>
<td width="9%" class="verdanasmall"><br> </td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="c" onclick="doSubmit(document.form1)">
User group</td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="n" onclick="document.form1.submit()">
Name</td>
</tr>
<tr>
<td height="20" class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="a" onclick="document.form1.submit()">
All</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table>
<br>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletitle">
<tr>
<td height="21">
<div align="center">
<input name="Submit" type="submit" class="Submitbutton" value="Save"> &nbsp;
<input name="reset" type="reset" class="Submitbutton" value="Reset">
</div></td>
</tr>
</table>
<br>

</form>
</center>
</body>
</html>

NinjaTurtle
12-10-2002, 02:51 AM
this is the Screen:

glenngv
12-10-2002, 03:53 AM
I didn't know what the select's values look like, I assumed they are the same with the select's text property.

Anyway, here is the new code:


<%
dim strOptionSelectedUsers,arrSelectedUsers,i,item,j
TempSysUser = request.QueryString("list2")
arrSelectedUsers = split(TempSysUser,",")
response.write "list2 items: " & ubound(arrSelectedUsers) & "<br>"
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
response.write i & ": " & arrSelectedUsers(i) & "<br>"
SplitID = split(arrSelectedUsers(i),"$#")
for j = 0 to ubound(SplitID)
response.write "j: " & SplitID(1) & "<br>"
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & SplitID(0) & """>" & SplitID(1) & "</option>" & VbCrLf
next
next
%>

NinjaTurtle
12-11-2002, 08:43 AM
i found that the coding make duplicate value whne the form was submitted.

so i changed a bit for the coding:
<%
dim strOptionSelectedUsers,arrSelectedUsers,i,item,j, userID, userName

TempSysUser = request.QueryString("list2")
arrSelectedUsers = split(TempSysUser,",")
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
SplitID = split(arrSelectedUsers(i),"$#")
for j = 0 to ubound(SplitID)
UserID = SplitID(0)
userName = SplitID(1)
next
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & UserID & """>" & userName & "</option>" & VbCrLf
next
%>

And now there are no more duplicate value, but problem is when the second time the form has been submitted, i get error:

Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: 1]'
/sdd/SystemAccess.asp, line 102

And the line no 102 suppost is the line : userName = SplitID(1)
if i change the statment to : userName = SplitID(0), it's work!!!
ofcos what i need is : userName = SplitID(1)

glenngv
12-11-2002, 09:55 AM
try this:

<%
dim strOptionSelectedUsers,arrSelectedUsers,i,item,j
TempSysUser = request.QueryString("list2")
arrSelectedUsers = split(TempSysUser,",")
response.write "list2 items: " & ubound(arrSelectedUsers) & "<br>"
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
response.write "<br>loop " & i & ": " & arrSelectedUsers(i) & "<br>"
SplitID = split(arrSelectedUsers(i),"$#")
response.write "ubound(SplitID): " & ubound(SplitID) & "<br>"
if ubound(SplitID)=1 then
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & SplitID(0) & """>" & SplitID(1) & "</option>" & VbCrLf
end if
next
%>

keep the response.writes temporarily for debugging purposes

NinjaTurtle
12-12-2002, 10:57 AM
is ok, the error is no more occured but next problem is come, that's is Your new source code only display the latest selected items, previous records will gone.

example: first time i select two users from the ledt list to right list, later i sort the left list box by Usergroup(Page will refresh), the list will filter out some unused records, and then i choose another new user from the left list, so total the right list having 3 users, but from ur new source code i only can get 1 record inside the right list when i click the radio button to do sorting again....

glenngv
12-13-2002, 03:35 AM
did you change ALL occurrences of document.form1.submit() as I said in my previous post?

like this:

<input type="radio" name="sortby" value="c" onclick="doSubmit(this.form)">

and for select:

<select name="usergroup" class="txtbox"
onChange="document.form1.sortby[0].checked=true;doSubmit(this.form)">

where the doSubmit() function is:


<script type="text/javascript">
//this function selects all items in list2 combo so that each item is submitted to the server
function doSubmit(f){
for (var i=0;i<f.list2.options.length;i++){
f.list2.options[i].selected = true;
}
f.submit();
}
</script>

NinjaTurtle
12-13-2002, 07:11 AM
yes i did, but dunno y cannot.

bcos the first time the page refresh the ubound(SplitID) = 0, that's meant my first time selected record will remain when i drag a new record to the right list and click again the radio butto to refresh the page again, then the first time record is gone, left the latest record only...

glenngv
12-13-2002, 07:47 AM
it's hard to visualize without seeing the actual page running. Do you have the page online? Or maybe a couple of screenshots if possible

NinjaTurtle
12-13-2002, 08:03 AM
ok, u can go to here:

http://www.lhhb.com/intranet/testing/testing.asp

test this example:

1. select two usres from left
2. click User group(refresh the left list)
3. select 1 user from left
4. click User group again(refresh the left list)

glenngv
12-13-2002, 08:29 AM
ok, change the option's value. see the modified part in bold:


<%
dim strOptionSelectedUsers,arrSelectedUsers,i,item,j
TempSysUser = request.QueryString("list2")
arrSelectedUsers = split(TempSysUser,",")
response.write "list2 items: " & ubound(arrSelectedUsers) & "<br>"
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
response.write "<br>loop " & i & ": " & arrSelectedUsers(i) & "<br>"
SplitID = split(arrSelectedUsers(i),"$#")
response.write "ubound(SplitID): " & ubound(SplitID) & "<br>"
if ubound(SplitID)=1 then
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & arrSelectedUsers(i) & """>" & SplitID(1) & "</option>" & VbCrLf
end if
next
%>


I suggest you use form method POST instead of GET. As you notice, the form data are appended in the URL. The length of URL has a limit. This could get very long since the user can add as many users as he wants. If the URL exceeds its limit, not all form data will be submitted, hence they will not be retrieve by the server-side code. If you change to POST, change all Request.Querystring to Request.Form

NinjaTurtle
12-13-2002, 11:00 AM
it's work perfectly..... Tq.... tq.... tq.....very very very much!!!

NinjaTurtle
12-16-2002, 10:50 AM
hello, it's me again.
i face another problem, how if i want to edit/delete the student from previous setting? how to make it?

ex:

1st time i add 2 users into the same category, later i want to delete 1 user and then drag new student into the list box and save.

i found the error:
Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range: '[number: 0]'

And there are three tables involved:
Category, User, CategoryUser.

glenngv
12-17-2002, 02:48 AM
I can't reproduce the error. Can you enumerate the steps you took before the error occurred?

NinjaTurtle
12-17-2002, 03:25 AM
dear,

no, that is error occured when the page is launch, bcos i did the database retrive, here is the addition ASP coding.


<%
dim strOptionSelectedUsers,arrSelectedUsers,i,item,j
dim SystemList
SystemList = request.Form("SystemList")
SystemList = split(SystemList,"$#")
response.write "cc: "&SystemList(0)
IF SystemList(0)<>"" then
dim SysUser, rsSysUser,strSQLSysUser, OptionSysUser, rsSysUserid,rsSysUsername,rsSysUsergroup
strSQLSysUser = "SELECT FAllowUserID FROM tbSystemAccess where FSystemCode='"&trim(SystemList(0))&"'"' and FCompanyCode='"&Session("CompanyCode")&"' AND FAllow='a' order by FAllowUserID"
set rsSysUser = server.createObject("ADODB.Recordset")
rsSysUser.Open strSQLSysUser, int_databasepath
'OptionSysUser = ""
If not rsSysUser.EOF and not rsSysUser.BOF then
Do Until rsSysUser.EOF
rsSysUserid = trim(rsSysUser("FAllowUserID"))
rsSysUsername = trim(rsSysUser("FAllowUserID"))
rsSysUsergroup = trim(rsSysUser("FAllowUserID"))
OptionSysUser = OptionSysUser & _
"<option value='"&rsSysUserid&"$#"&rsSysUsername&"'>"&rsSysUsername& " ("&rsSysUsergroup&")</option>"&vbcrlf
rsSysUser.movenext
Loop
end if
END IF

TempSysUser = request.Form("list2")
arrSelectedUsers = split(TempSysUser,",")
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
SplitID = split(arrSelectedUsers(i),"$#")
if ubound(SplitID)=1 then
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & arrSelectedUsers(i)& """>" & SplitID(1) & "</option>" & VbCrLf
end if
next

%>

glenngv
12-17-2002, 03:47 AM
on first load of the page request.Form("SystemList") will be empty.
and if you split an empty string, ubound returns -1
So you should check first if the array contains an element or not by checking ubound.


SystemList = request.Form("SystemList")

response.write "SystemList: " & SystemList & "<br>"

SystemList = split(SystemList,"$#")

response.write "ubound(SystemList) = " & ubound(SystemList) & "<br>"

if ubound(SystemList)>-1 then 'if nothing to split, ubound returns -1
response.write "cc: " &SystemList(0) & "<br>"
if SystemList(0)<>"" then
'code here
end if
end if


you might want to check this thread that discussed a "valid" array:
http://codingforums.com/showthread.php?s=&threadid=8491&perpage=15&pagenumber=2#post47382

NinjaTurtle
12-17-2002, 04:06 AM
its work, but now the problem is how to put the previous record join with the new record????
actually there is one record "gohkockhwie" under "Inventory" but the record wont appear at the right list, and how if the user unselect the prvious record(gohkockhwie) and do sorting(page will refresh) so i need to do checking too?

i really hav no idea.

glenngv
12-17-2002, 04:18 AM
I can't get what you mean. Maybe you can enumerate the steps to be taken

NinjaTurtle
12-17-2002, 04:24 AM
TQ. i solve the problem... tq....

NinjaTurtle
12-18-2002, 02:51 AM
dear,

now i want to submit the form to another ASP page to do records insert into database. Its not work bcos the form i used it for refresh by sorting and retrieve databasse record. so now the problem is i want to send the list box(right) to another page to do the insert database process... how?

i try to do it in the same page, detect the "Save" button value to do insertion database. But it can not get the listbox value, but the select drop down list i can get it.

this is the coding.


<html>
<head>
<Script language="JavaScript">
function doSubmit(f){
for (var i=0;i<f.list2.options.length;i++){
f.list2.options[i].selected = true;
}
f.submit();
}
</Script>
</head>
<%

dim Sorting,usergroup,TempSysUser,SystemList
SystemList = request.Form("SystemList")
SystemList = split(SystemList,"$#")
Sorting = request.Form("sortby")
usergroup = request.Form("usergroup")
TempSysUser = request.Form("list2")
response.write TempSysUser&"<BR>"

if request.form("SaveBttn")="Save" then
response.write request.Form("SystemList")&"<BR>"
dim ConfirmSysUser, arrConfirmSysUSer,c
arrConfirmSysUSer = split(request.Form("list2"),",")
response.write TempSysUser&"<BR>"

for c = 0 to ubound(arrConfirmSysUSer)
ConfirmSysUser = split(arrConfirmSysUSer(c),"$#")
if ubound(ConfirmSysUser)>=1 then
response.write "i: "&arrConfirmSysUSer(c) &"<BR> 0: "
response.write (ConfirmSysUser(0)) &"<BR>1: "
response.write (ConfirmSysUser(1)) &"<BR>2: "
response.write (ConfirmSysUser(2)) &"<BR>"
'strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & arrSelectedUsers(i)& """>" & SplitID(1)&" ("& SplitID(2)&")" & "</option>" & VbCrLf
end if
next

response.write "<HR>"
response.write "<B>Record saved!</b>"
response.end
end if
dim connPro, rsPro, strOption, strSQL, rssystemcode,rssystemdesc
strSQL = "SELECT * FROM tbSystemname where fcompanycode='"&Session("CompanyCode")&"' and fupdstat='A' order by fsystemcode"
set rsPro = server.createObject("ADODB.Recordset")
rsPro.Open strSQL, int_databasepath
strOption = ""
If not rsPro.EOF and not rsPro.BOF then
dim selectedRecord
Do Until rsPro.EOF
rssystemcode = trim(rsPro("fsystemcode"))
rssystemdesc = trim(rsPro("fsystemdesc"))
if ubound(SystemList)>-1 then
IF rssystemcode=SystemList(0) then
selectedRecord = "Selected"
else
selectedRecord = ""
end if
end if
strOption = strOption & _
"<option value='"&rssystemcode&"$#"&rssystemdesc&"'" &selectedRecord&">"&rssystemdesc&"</option>"&vbcrlf
rsPro.movenext
Loop
else
strOption = "<option value=''>No Record Found.</option>"
end if
rsPro.Close
set rspro = nothing
set connPro = nothing

strSQL = "SELECT * FROM Sysuser where faccountstatus='a' order by fname, fgroup "
set rsUser = server.createObject("ADODB.Recordset")
rsUser.Open strSQL, int_databasepath
strOptionUser = ""
If not rsUser.EOF and not rsUser.BOF then
Do Until rsUser.EOF
rsfid = trim(rsUser("fid"))
rsfname = trim(rsUser("fname"))
rsfgroup = trim(rsUser("fgroup"))
strOptionUser = strOptionUser & _
"<option value='"&rsfid&"$#"&rsfname&"$#"&rsfgroup&"'>"&rsfname& " ("&rsfgroup&")</option>"&vbcrlf
rsUser.movenext
Loop
else
strOptionUser = "<option value=''>No Record Found.</option>"
end if
rsUser.Close
set rsUser = nothing
set connUser = nothing

dim connCom, rsCom, strOptionCom, rsgroup
strSQL = "SELECT DISTINCT(fgroup) FROM Sysuser order by Fgroup"
set rsCom = server.createObject("ADODB.Recordset")
rsCom.Open strSQL, int_databasepath
strOptionCom = ""
If not rsCom.EOF and not rsCom.BOF then
Do Until rsCom.EOF
rsgroup = trim(rsCom("fgroup"))
strOptionCom = strOptionCom & _
"<option value='"&rsgroup&"'>"&rsgroup& "</option>"&vbcrlf
rsCom.movenext
Loop
else
strOptionCom = "<option value=''>No User Group Found.</option>"
end if
rsCom.Close
set rsCom = nothing
set connCom = nothing

dim strOptionSelectedUsers,arrSelectedUsers,i,item,j
TempSysUser = request.Form("list2")
if TempSysUser="" then
if ubound(SystemList)>-1 then 'if nothing to split, ubound returns -1
IF SystemList(0)<>"" then
dim SysUser, rsSysUser,strSQLSysUser, OptionSysUser, rsSysUserid,rsSysUsername,rsSysUsergroup
strSQLSysUser = "SELECT FAllowUserID FROM tbSystemAccess where FSystemCode='"&trim(SystemList(0))&"' and FCompanyCode='"&Session("CompanyCode")&"' AND FAllow='a' order by FAllowUserID"
set rsSysUser = server.createObject("ADODB.Recordset")
rsSysUser.Open strSQLSysUser, int_databasepath
OptionSysUser = ""
If not rsSysUser.EOF and not rsSysUser.BOF then
Do Until rsSysUser.EOF
rsSysUserid = trim(rsSysUser("FAllowUserID"))
rsSysUsername = trim(rsSysUser("FAllowUserID"))
rsSysUsergroup = trim(rsSysUser("FAllowUserID"))
response.write "User ID : "&rsSysUserid
OptionSysUser = OptionSysUser & _
"<option value='"&rsSysUserid&"$#"&rsSysUsername&"$#"&rsSysUsergroup&"'>"&rsSysUsername& " ("&rsSysUsergroup&")</option>"&vbcrlf
rsSysUser.movenext
Loop
end if
END IF
end if
else
arrSelectedUsers = split(TempSysUser,",")
dim SplitID
for i = 0 to ubound(arrSelectedUsers)
SplitID = split(arrSelectedUsers(i),"$#")
if ubound(SplitID)>=1 then
strOptionSelectedUsers = strOptionSelectedUsers & "<option value=""" & arrSelectedUsers(i)& """>" & SplitID(1)&" ("& SplitID(2)&")" & "</option>" & VbCrLf
end if
next
end if
%>
<body>
<center>
<form name="form1" method="POST">
<table width="100%" border="0" align="center" cellspacing="0">
<tr>
<td width="70%" >System Access<br> <br> </td>
<td align="right" width="30%" class="Verdanatext">&nbsp;</td>
</tr>
<tr>
<td colspan="2" > <table width="85%" border="0" align="center" class="tabletitle">
<tr>
<td width="21%" >System Name</td>
<td width="79%" ><select name="SystemList" onchange="document.form1.submit()">
<option value="">-- Select a system --</option>
<%=strOption%> </select></td>
</tr>
<tr>
<td valign="top" >Select User</td>
<td class="bbodyTD">
<table width="90%">
<tr class="browtitleTD">
<td width="37%" colspan="2" class="verdanabbodytext">Company Staff</td>
<td width="8%">&nbsp;</td>
<td width="46%"><div align="center">System User</div></td>
</tr>
<tr>
<td colspan="2"> <div align="left">
<select multiple size="10" name="list1" style="width:280px" ondblclick="move(document.form1.list1,document.form1.list2)">
<%=strOptionUser%>
</select>
</div></td>
<td width="8%"><input name="B1" type="button" class="Smallbutton" onclick="move(document.form1.list1,document.form1.list2)" value=" &gt;&gt; ">
<BR>
<input name="B2" type="button" class="Smallbutton" onclick="move(document.form1.list2,document.form1.list1)" value=" &lt;&lt; "><BR><BR></td>
<td width="46%"> <div align="center">
<select multiple size="10" name="list2" style="width:280px" ondblclick="move(document.form1.list2,document.form1.list1)">
<%=strOptionSelectedUsers%><%=OptionSysUser%>
</select>
</div></td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall">&nbsp;</td>
</tr>
<tr>
<td class="verdanasmall">Sort by:</td>
<td colspan="3" class="verdanasmall"><input type="radio" name="sortby" value="cc">
Selected user group: <select name="usergroup" class="txtbox" onChange="document.form1.sortby[0].checked=true;doSubmit(document.form1)">
<option value="0" selected>-- Select user group --</option>
<%=strOptionCom%> </select> </td>
</tr>
<tr>
<td width="9%" class="verdanasmall"><br> </td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="c" onclick="doSubmit(document.form1)">
User group</td>
</tr>
<tr>
<td class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="n" onclick="doSubmit(document.form1)">
Name</td>
</tr>
<tr>
<td height="20" class="verdanasmall">&nbsp;</td>
<td colspan="3" class="verdanasmall"> <input type="radio" name="sortby" value="a" onclick="document.form1.submit()">
All</td>
</tr>
</table>
</td>
</tr>
</table></td>
</tr>
</table>
<br>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0" class="tabletitle">
<tr>
<td height="21">
<div align="center">
<input name="SaveBttn" type="submit" class="Submitbutton" value="Save"> &nbsp;
<input name="reset" type="reset" class="Submitbutton" value="Reset">
</div></td>
</tr>
</table>
<br>
</form>
</center>
</body>
</html>

glenngv
12-18-2002, 03:40 AM
That's because all the options in the listbox at the right are not selected. All the options should be selected in order for them to be submitted to the server. That's why I made the code that selects all the options before submitting which is being called on onclick of the radio buttons and on onchange of the Select User Group drop-down. Since the Save button is already a submit button, you should select all the options on onclick of it.

These are the changes you need to do...

Change the doSubmit() function to this:

function doSubmit(f){
selectAllOptions(f);
f.submit();
}

then add this function:

function selectAllOptions(f){
for (var i=0;i<f.list2.options.length;i++){
f.list2.options[i].selected = true;
}
}

then in the Save button:

<input name="SaveBttn" type="submit" class="Submitbutton" value="Save" onclick="selectAllOptions(this.form)">

NinjaTurtle
12-18-2002, 04:29 AM
Its work!!! Thank you.

so i cannot do process at new ASP file???



Can i know how pld r u? and how u learn all these.... u r professional = Expert!!!

glenngv
12-18-2002, 05:03 AM
Of course you can still submit the form to another page by changing the form action using javascript. But I suggest you do it in the same page since you are only saving the data in the database. What you can do is modularized it by putting them in subroutines. That will make the code clearer and easy to modify.

I'm a "little" older than you. :D
I learned all these thru experience.
Aside from ASP, you have to grasp the principle behind HTML, like options in a multiple-select dropdown will not be submitted if there is no item selected, unchecked radio buttons and checboxes are not submitted, and the like...
Some of them are written on the books but others you would just find it yourself :)