Solved

JSP Field removal on fly

Posted on 2004-08-20
2
249 Views
Last Modified: 2012-05-05
I have two textfields in a JSP page

I want to remove these fields BUT without touching the JSP.

There are 2 phase of this small project as mentioned below:

In first phase, remove the first text field. In the second remove the second text field.

I need to use JavaScript for hide and show the fields in the JSP

Here is a brief example :

<html>
<head>
      <title></title>
</head>

<body>
<P>Field 1: Remove this field in phase I using Javascript</P>
<P><INPUT name=FIELD1 value=""></P>
<P>Field 2: Remove this field in phase II using Javascript</P><INPUT
name=FIELD2 value="">


</body>
</html>

Please advise accordingly (a code snippet will be a lot help)

Thanks a lot
0
Comment
Question by:Java_Problem
2 Comments
 
LVL 2

Expert Comment

by:beermequik
ID: 11854211
<body>
<P>Field 1: Remove this field in phase I using Javascript</P>
<P><INPUT ID="FIELD1" name=FIELD1 value=""></P>
<P>Field 2: Remove this field in phase II using Javascript</P><INPUT ID="FIELD2"
name=FIELD2 value="">


</body>

<SCRIPT>
function hide(id){
    var elem = document.getElementById(id);
    elem.style.visibility = "hidden";
}
</SCRIPT>

use js to call hide("FIELD1") or hide("FIELD2");


0
 
LVL 21

Accepted Solution

by:
MogalManic earned 125 total points
ID: 11856181
1)label all of your html elements with 'id' attributes (i.e. <p id='fieldA'>...</p>)
2)Then in the javascript do the following
   aNode=document.getElementById('fieldA');  //Get the first field with ID=='fieldA'
   aNode.style.display='none';  //To Display again, use:display='block'
             OR
   aNodeList=document.getElementByName('fieldA');  //Get the list of fields with ID=='fieldA'
   for(i=0;i<aNodeList.length;i++) {
     aNodeList[i].style.display='none';  //To Display again, use:display='block'
   }


This has the advantage over setting the visibity in that the page will remove the space used by the hidden elements.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping2 challenge 13 90
topping3 challenge 14 79
Not needed 13 112
How to insert gas or chemical names in SQL server. For e.g. CO2 to CO₂. 5 75
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question