• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

JSP Field removal on fly

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
Java_Problem
Asked:
Java_Problem
1 Solution
 
beermequikCommented:
<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
 
MogalManicCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now