Click to See Complete Forum and Search --> : How to submit multiple options of a select to the sever? the


Lily
03-20-2003, 07:10 AM
Hello,all,

When submit a form, how can I send the selected options among a selection to the server side?

example:
....

<FROM>
<TABLE>
<TBODY>
<TR>
<TD>&nbsp;<BR><SELECT
style="WIDTH: 218px; HEIGHT: 246px" multiple size=15
name="unassignedUsers">
<OPTION value="lily">lily</OPTION>
<OPTION value="web">web</OPTION>
<OPTION value="developer">developer</OPTION>
</SELECT></TD>
</TR>

<TR>
<TD align=middle colSpan=2><BR><BR><INPUT type=submit onsubmit="submitBack()" value="Back to Home " name="backBtn"></TD>
</TR>
.....

When click on the "Back to Home" button, the "submitBack()" selects all the items of the select object, but, how can I get these items in the server side?

Best Regards.

Lily
03-20-2003, 08:21 PM
I encountered this problem in the project of developing a application on Websphere Portal Server. When submiting this form, I should submit all these options of the "unassignedUsers" selection to the server, and store them to database, so, when user close this session and login again, I can read all these unassignedUsers from database to display them to the user.

The server side cose is part of developing a portlet:

private void manageUser( PortletRequest request)
{
PortletSession session = request.getPortletSession();

try {
// Obtain the database connection object from the session
DBConnectionSpec connectionDBbean =
(DBConnectionSpec) session.getAttribute( SESSION_BEAN_CONNECT );

// Initialize the parameters of the SQL statement
DBSelect userDBbean = new DBSelect();
userDBbean.setConnectionSpec( connectionDBbean );

String submitBack = request.getParameter("backBtn");

if((submitBack != null) && (submitBack.equals("Back to Home")) ){//back
String sfLicense = (java.lang.String) (session.getAttribute(SESSION_SFEDIT_LICENSE));
String[] assUsers = (java.lang.String[])(request.getParameterValues("unassignedUsers"));

// the element num of the selected users
int userCount = assUsers.length;

for(int i = 1; i <= userCount; i++)
{
String addUserSql = "INSERT INTO CDLUSER VALUES(";
addUserSql = addUserSql + "'" + sfLicense + "'";
addUserSql = addUserSql + ",'" + assUsers[i] + "'";
addUserSql = addUserSql + ",'null','null','null'" + ")";

userDBbean.setCommand(addUserSql);

userDBbean.execute();
}
session.setAttribute( SESSION_BEAN_USERS, userDBbean );
session.setAttribute(SESSION_PAGE_TYPE,PAGE_ITEMDETAILFOREDIT);
}
}catch ( SQLException ex ) {
// Show error screen
session.setAttribute( SESSION_ERROR_TYPE, ERROR_SQLERROR );
session.setAttribute( SESSION_PAGE_TYPE, PAGE_ERROR );
}
}

...................

My confusion is whether I can use the "request.getParameterValues("unassignedUsers")" to get all the options? That means to operate a client side object and get all the values of it at the server side. Or, I can put the options to a session attribute at the client side and get the value from the session in the server side. Maybe, setting a hidden field to each option is another selection. I am not sure which is right and whcih is better?

Lily
03-20-2003, 08:43 PM
Sure, you are right.

I write the script :

function submitBack(){
var i = 0,remListNum;

remListNum = document.UserSelectedForm.mySelectList.options.length;

while( i < remListNum )
{
document.UserSelectedForm.mySelectList.options[i].selected = true;
i ++;
}
}

....
<TD><INPUT type=submit onsubmit="submitBack();return true" value="Back to Home" name="backBtn"></TD>
.....
my question is using which method to get these options' value at the server code? Thank you!

Lily
03-20-2003, 11:08 PM
Dave,

Thanks anyway! I have tried other ways and now seems it would be resolved.

Regards.

Lily