File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Getting html form name Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Getting html form name " Watch "Getting html form name " New topic
Author

Getting html form name

Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Hi all

I am having a jsp page with some form controls. Suppose, if I click on a radio button, it will transfer control to next jsp page and there I should be able to track which form has generated the request. And, depending on the form name again I have to forward the result of that jsp page to the previous page or any other jsp page.

In this situation I am trying to invoke a function in javascript when a radio button is clicked which has following code:



In this situation when I am checking a radio button I am getting error saying
document.formname.hiddenfld.value is null or not object


What actually I planned is, if I am able to set the formname in the hidden field, I can getParameter of that hidden field in next field and check for it's value there and subsequently I can forward to corresponding jsp page. But it didn't work. What else can be done?

Please clarify...
Ernesto Elias-Nieland
Ranch Hand

Joined: Sep 01, 2005
Posts: 53

Hi!

I dont't really understand your problem in detail but why are you using JavaScript for that kind of stuff ? You could better send your form data to a servlett which processes your form data and than forwards the results to a JSP page. To identify the sender of the request you can use a hidden form element which sends a action code from which your servlet can deside what to do.

Ernie


0x2B | ~0x2B
SCJD, SCJP 1.5, SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJA, IBM Test 150, 142, 700, 701, Oracle Test 1Z0-51
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Hi

Can you explain me clearly, how to send the action command from the form element to servlet. Any sample code is appreciated, as I am not good at using Servlets I have started using jsp/servlets few days back.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60791
    
  65

Moved to the HTML forum.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Darren Edwards
Ranch Hand

Joined: Aug 17, 2005
Posts: 69
I think what you're after is a way to tell which button was clicked on a form with many buttons?



In your servlet you can now check for the existence of the button.
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Hi all,

Is there any other way for me to know which form has generated the request in Servlet? i.e., I should be able to know the <formname> in my servelt.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60791
    
  65

A form is a client-side artifact. To need to know its name on the server-side indicates a flaw in design. Why do you need this information?
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
I have three forms in my project.

I am getting values into these 3 forms from the database using some controller JSP's by interacting with the Bean classes. I need some set of values to be displayed in all the 3 jsp pages. What I did during designing of my first form is I binded the database values to a session for use in any jsp page. I forwarded the controller jsp page to my main JSP. In that situation it was fine.

But during the design time of my 2nd jsp what I found was I need the same controller jsp to transfer the same set of values to the 2nd jsp also. Here I faced a problem, as I need to forward the controller JSP to both forms. Later I noticed that my 3rd form also needs some of the values from one of the controller jsp.

Here I am thinking of resolving it as, "Identifying the request generated by the form using it's FORM NAME and depending on the name of the form I want to forward the page to any of my 3 main forms".

Can u please suggest me how I can achieve this task.

What I was doing till now is to get values into a dropdown list box I am writing a bean class to get values from database, then I am writing a controller jsp where I am getting values from bean class stored into an arraylist which is then bind to a session object and then it is used in the Main JSP. Depending on the value selected in the listbox again I have to invoke another method from the bean class and get those values, even for this task I have a controller jsp which does the job and again it is bind in session object which is again used in my Main jsp, here after binding the arraylist values to a session I need to transfer control again to my Main JSP

[ July 22, 2006: Message edited by: Sree Mami ]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Easier solution, put a hidden filed on the page with a value where you are at.

Eric
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Yes, I am using a hidden field and as I am aware of my form name I am directly passing it as the value to that hidden field. When I transfer control to a jsp page, I am retrieving the hidden field value there and comparing it with a string variable declared there with the hidden field value and transferring control to subsequent JSP page. Here my problem is that, I am able to transfer control to first <jsp:forward page="first.jsp"> page only, the rest are being ignored. What shall I do?

My code is:



Where hidden1 is the Hidden field which is declared in all the 3 forms with same name...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60791
    
  65

Is that the actual code that is in your page?
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Ya, it was the actual code which was not working,





so I need to write different controller JSP's for forwarding the results to each of those main forms...
[ July 26, 2006: Message edited by: Sree Mami ]
Sree Mami
Ranch Hand

Joined: Jul 13, 2006
Posts: 75
Ya, I am getting some error, I will try to find it for myself and will get back to you, actually I forgot to open and close scriptlet tag before forwarding the page to one of the main forms..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting html form name
 
Similar Threads
How to keep selected radio button after page refresh
Making a input text field readonly..
using ajax and struts iterate tags
Struts Validator Issues
to get the radio value in another jsp page