Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

write jsp form so user can control number of fields

Thread view: 
ghadley_00@yahoo.com - 02 Jan 2006 19:54 GMT
Hi,

I currently have an html form with which I gather the same information
for 5 items, and then post all the data for processing to a jsp file. I
would like to make a form (using jsp or php) that allows the user to
choose how many items they would like to compare (1 through 5) , and
then have the form change to list the appropriate set(s) of form entry
fields, with each field's variable appropriately named uniquely (e.g.
at present I have Color1, Color2, Color3, Color4, Color5 all as
variables submitted via my form, I would like this naming convention to
continue).

In other words, if the user chooses to only compare 3 items, I would
like for only 3 sets of entry fields to be presented, for each of which
the field names would be fieldname1, fieldname2, fieldname3.

To accomodate the java class file I am sending the data to for
processing, I would also like the code to pass zero values for the
fields not chosen. In other words, if only 3 items are chosen, the
values that would have been submitted for items 4 and 5 are submitted
as zeros.

Any help that can be provided would be greatly appreicated. A
solutionin either jsp or php would be fine.

Best wishes,

George Hadley
ghadley_00@yahoo.com
Aj-India - 03 Jan 2006 04:23 GMT
you could use a script function to get the number of fields from the
user. Then you can use innerHTML to generate those fields.
Aray - 03 Jan 2006 07:38 GMT
<ghadley_00@yahoo.com>
??????:1136231651.284256.45280@o13g2000cwo.googlegroups.com...
> Hi,
>
[quoted text clipped - 11 lines]
> like for only 3 sets of entry fields to be presented, for each of which
> the field names would be fieldname1, fieldname2, fieldname3.

You don't have to name these fileds different. use the same name, for
example, "myFieldName".
if you set the form method to get, the url sames like this:
   http://www.aray.com/xxx.jsp?myFieldName=color1&myFieldName=color2&myFieldName=color3

In jsp file, you may use
   String fieldValues[] request.getParameterValues("myFieldName");
to get these fields. and String array fieldValues's value are bellow.
   fieldValues[0] == "color1";
   fieldValues[1] == "color2";
   fieldValues[2] == "color3";

> To accomodate the java class file I am sending the data to for
> processing, I would also like the code to pass zero values for the
> fields not chosen. In other words, if only 3 items are chosen, the
> values that would have been submitted for items 4 and 5 are submitted
> as zeros.

allocate a new String array, and copy fieldValues's values to this array.

String newFieldValues[] = new String[5];
int i;
for(i=0; i<fieldValues.length() && i<newFieldValues.length(); i++)
   newFieldValues[i]=fieldValues[i];
for(;i<newFieldValues.length(); i++)
   newFieldValues[i]="0";

> Any help that can be provided would be greatly appreicated. A
> solutionin either jsp or php would be fine.
[quoted text clipped - 3 lines]
> George Hadley
> ghadley_00@yahoo.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.