• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Getting html form name

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to the HTML forum.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Easier solution, put a hidden filed on the page with a value where you are at.

Eric
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that the actual code that is in your page?
 
Sree Mami
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic