Solved

JSP Field removal on fly

Posted on 2004-08-20
2
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

733 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