Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > Servlets
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 25th, 2005, 05:08 PM
Registered User
 
Join Date: Apr 2005
Location: tuscaloosa, al, USA.
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




Reply With Quote
  #2 (permalink)  
Old April 26th, 2005, 05:35 PM
Friend of Wrox
 
Join Date: Jul 2004
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 08:29 AM.


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