Solved

JSP Field removal on fly

Posted on 2004-08-20
2
230 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
Comment Utility
<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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now