Depends... Do you want this all to happen on the client only, or do you want a
round-trip to the server?
If client-only, just wrap the optional elements in a <div> tag, then use the
onChange event of the <select> element to show the appropriate group (you'll
need to hide eerything else of course... I usually just hide everything and
then show the appropriate <div>). So, for instance:
<html><head><title>test</title>
<script>
function showOptionals(obj) {
div1.style.display = "none";
div2.style.display = "none";
obj = eval(obj.value);
obj.style.display = "block";
}
</script>
</head>
<body>
<form name="theForm" method="post" action="mywaction">
<select onChange="showOptionals(this);" name="theSelect">
<option value="div1">User</option>
<option value="div2">Admin</option>
</select>
<!-- Put all the common input elements here -->
<div id="div1" style="display:none;">
<!-- Optional elements for the User role -->
</div>
<div id="div2" style="display:none;">
<!-- Optional elements for the Admin role -->
</div>
</form>
</body>
</html>
If you don't want to do it via scripting, then you submit the form as a result
of onChange of the select, and in your JSP code you change the style of the
appropriate <div> based on the option selected, something like:
<%
String div1Style = "display:none;";
String div2Style = "display:none;";
String whatGroup = (String)request.getParameter("theSelect");
if (whatGroup.equalsIgnoreCase("div1")) {
div1Style = "display:block;";
}
if (whatGroup.equalsIgnoreCase("div2")) {
div2Style = "display:block;";
}
%>
<html><head><title>test</title>
</head>
<body>
<form name="theForm" method="post" action="mywaction">
<select onChange="theForm.submit();" name="theSelect">
<option value="div1">User</option>
<option value="div2">Admin</option>
</select>
<!-- Put all the common input elements here -->
<div id="div1" style"<%=div1Style%>">
<!-- Optional elements for the User role -->
</div>
<div id="div2" style="<%=div2Style%>">
<!-- Optional elements for the Admin role -->
</div>
</form>
</body>
</html>
Roughly anyway... I haven't tested this, might be some minor problems, but you
get the general idea.
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Wed, January 5, 2005 11:04 am, Ritchie Warsito said:
> hi there.
> If I were to have a dropdown select (which I don't know yet also how to
> populate from database), and I select an option say User.
> I want something (part of a form or such) to show.
>
> Example:
> Adding useraccounts. There are 3 roles, User, Admin & Office.
> Field Username, Password, Re-Enter Password and Role are common.
> Based on what I choose in the Role select dropdown, below that there
> will come another field or fields.
> So for User, another field (or table of fields) will show where to add
> his different Customer ID's.
> For Office, another field will show for let's say his Office ID.
>
> How can I accomplish this? I'm sorry if I ask stupid questions, but
> because of my experience with PHP only where these things are possible I
> really would like to have them in jsp/struts too.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
On Wed, January 5, 2005 11:04 am, Ritchie Warsito said:
> hi there.
> If I were to have a dropdown select (which I don't know yet also how to
> populate from database), and I select an option say User.
> I want something (part of a form or such) to show.
>
> Example:
> Adding useraccounts. There are 3 roles, User, Admin & Office.
> Field Username, Password, Re-Enter Password and Role are common.
> Based on what I choose in the Role select dropdown, below that there
> will come another field or fields.
> So for User, another field (or table of fields) will show where to add
> his different Customer ID's.
> For Office, another field will show for let's say his Office ID.
>
> How can I accomplish this? I'm sorry if I ask stupid questions, but
> because of my experience with PHP only where these things are possible I
> really would like to have them in jsp/struts too.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]