Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes HTML, CSS and JavaScript and the fly likes delete form field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "delete form field" Watch "delete form field" New topic
Author

delete form field

Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Is it possible to delete a form field? I'm trying to get the field to be null so that my JSP doesn't see it as a parameter.

I tried the following, but it returns the string "null" when I do request.getParameter() in my JSP.



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61092
    
  66

I'd just beef up the server-side code so that it will ignore the parameter when the value is null, but if you insist on dealing with it client-side you can use DOM manipulation to remove the element from the page.

Using the 'display:none' CSS rule won't work since different browsers treat it differently (some will still submit the parameter, some won't).

Client-side manipulation is just too squirrelly for my tastes so I'll repeat my recommendation to deal with it server-side.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
Hi Jeanne,

When I worked with IE4 a few years ago it didn't submit disabled fields. We had to write special JS to enable and re-disable read-only fields either side of the submit (using the readOnly property had other issues, in case you're wondering).

I dunno if that's still the case but it may be worth a shot.

Jules
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Bear,
I'm sort of stuck with this code as it is in a framework developed by another team. I am going to try to get them to change it, but I have to work around this problem in the meantime. So unless you know a way of changing the parameters in the request, I have to do this.

This is a hidden field, so it wouldn't be displayed anyway. I'll try the DOM idea and Jules' disable suggestion tomorrow.

I will put a comment that the javascript is a hack and should be removed
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150

Both of those solutions work in IE. Unfortunately, neither works in Netscape 4.7, which we are required to support.

I'll do some more research on netscape 4.7 and see if I can come up with anything.
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
I have a solution for Netscape 4.7 but it involves deleting more than just a form field!

Jules
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30361
    
150



It doesn't seem possible to get arond this in NS 4.7. I wound up doing a server side hack (copying the method) until it is fixed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: delete form field