aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes How to access the Form in another page ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How to access the Form in another page ?" Watch "How to access the Form in another page ?" New topic
Author

How to access the Form in another page ?

Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Hi ,

I want to know how to access the name of the form in another page as a parameter . I have two forms and I need to check from which form the parameters are being passed can that be done ?

For Example

Page 1 :
<form name="b">...</form>[/code]


I want to be able to perform different operations for different forms. Can that be done ?

Thanks and Regards,
Varun


All's well that Debugs well .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Form names are not passed as part of the request. You'll need to find some other way. Perhaps a hidden input?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Thank you for the reply !

I thought of it too . But the the same problem arises because I still need to know from which form the hidden value is being passed from .

Regards
Varun
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

How is that a problem? You can use a unique value.

You're also not thinking about this quite right. What form it comes from is binding things too closely. Rather, the hidden input can identify a value for what's supposed to happen that's independent of anything else. That way, anything can supply that value, and it doesn't have to be a specific form, or even a form at all. Loose binding is the way to go.
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Thanks for the quick reply ,

I am having trouble understanding what you are saying .

Regards
Varun
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

You are attempting to use the name of the form as a switch to do different operations, correct?

If so, this is a poor approach and employs "close binding". This means that the operations are closely tied to the what initiating them, in this case a form. This is bad for a number of reasons, the most important being that the operation must always come from a form; what if you eventually want to use Ajax? Or a simple link? You can't because you closely bound the operation to a form.

Rather, if the "switch" for the operation were simply another parameter, whose value can be set by anything, then your operation is much more flexible in how it can be called.

It's sort of like trying to tie what a Java method does by finding out what method called it. You'd never do that -- you'd pass a parameter that tells the method what to do.

Bottom line: never tie an operation strongly to where it comes from -- use parameters to provide information to the operation.
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Thank you !

I got it ! But my intention is to use parameters only ! But I want to pass the form's name as a parameter and I am not using Switch per say . What I am trying to do is use a 'If' condition where i check which form the parameters are coming from and then perform accordingly .

Regards
Varun
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

Again, the form name is not a good thing to use. Use a parameter whose name is descriptive of what it is switching (whether you use a switch statement or if statement, it's still called switching) and values that are descriptive of what the switch is selecting. Stop thinking of the form name as anything relevant. It can't be sent as part of the submit, and it's just wrong thinking as outlined in my previous reply.
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Thank you ,

I have got the point . But still I am now stuck with the problem of how to switch between the operations .

Regards
Varun
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61420
    
  67

What's the specific problem? If it's in a servlet, please open a new topic in the servlets forum on how to switch between operations given a parameter with values that identify different operations.

(Have you considered using different servlets rather than ganging it all up into one?)
Varun Nambuthiri
Ranch Hand

Joined: Sep 20, 2010
Posts: 76
Thank you !

I have managed to get around the problem by passing making some changes in the code . And as you suggested I did it with variables !

Thank you again
Regards
Varun
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to access the Form in another page ?