Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Servlets section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 25th, 2005, 05:08 PM
Registered User
 
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Generating html tags dynamically

I have following page which is generated using servlet..

<body>
<table>
<tr><td>Search
<form id="the form">
</td></tr>
<td><input type="text" name="searchValue1" value=""></input></td>
<td><select class = "FormField" name="searchElement1">
<option value="libId1"> Name1 </option>
<option value="libId2"> Name2 </option>
<option value="libId3"> Name3 </option>
<option value="libId4"> Name4 </option>
<option value="libId5"> Name5 </option></td>
</select>
<td><select class = "FormBool" name="boolElement1" >
<option value=" ">No Bool</option>
<option value="OR">OR</option>
<option value="AND">AND</option></td>
</select></form>
</td></tr>
</table>
</body>

Now what i want is that when the user chooses OR or NOT from the drop down box ..then the following code should be added to existing code..that is making number of elements on page double in number..
like..

<body>
<table>
<tr><td>Search
<form id="the form">
</td></tr>
<td><input type="text" name="searchValue1" value=""></input></td>
<td><select class = "FormField" name="searchElement1">
<option value="libId1"> Name1 </option>
<option value="libId2"> Name2 </option>
<option value="libId3"> Name3 </option>
<option value="libId4"> Name4 </option>
<option value="libId5"> Name5 </option></td>
</select>
<td><select class = "FormBool" name="boolElement1" >
<option value=" ">No Bool</option>
<option value="OR">OR</option>
<option value="AND">AND</option></td>
</select>

<td><input type="text" name="searchValue2" value=""></input></td>
<td><select class = "FormField" name="searchElement2">
<option value="libId1"> Name1 </option>
<option value="libId2"> Name2 </option>
<option value="libId3"> Name3 </option>
<option value="libId4"> Name4 </option>
<option value="libId5"> Name5 </option></td>
</select>
<td><select class = "FormBool" name="boolElement2" >
<option value=" ">No Bool</option>
<option value="OR">OR</option>
<option value="AND">AND</option></td>
</select>
</form>
</td></tr>
</table>
</body>

How can this be done..and i wuld be reading the contents of text boxes and drop down list later using servlet..

Any help in this regard would be greatly appreciated..

Thanking you in advance
Sachin




 
Old April 26th, 2005, 05:35 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
Default

put your html in a string and use if statements,

String string1 = <first lot of text>
String string2 = <optional text 1>
String string3 = <optional text 2>



if (OrNot.equals(OR)) //assuming another string OrNot has the users response
{
    string1 = string1 + string2
}
else
{
    string1 = string 1 + string 3
}

Then write the string to the page

Alternatively you could create a loop to do something similar, this way you could create a variable number of fields.






Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamically generating Excel file sunitapandey Struts 3 November 23rd, 2006 03:53 AM
Generating ViewState Names Dynamically rfinks VB How-To 3 July 31st, 2006 11:47 AM
Dynamically Generating Textboxes Maxood PHP How-To 6 March 9th, 2006 09:14 AM
Generating anchor tags swwallace XSLT 3 March 8th, 2006 03:05 PM
Generating XML tags on the fly francislang XSLT 3 September 6th, 2004 05:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.