File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes Many form tags in html Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Many form tags in html" Watch "Many form tags in html" New topic

Many form tags in html

michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Is it possible to put a few different form tags in a html page and the page still works properly? I wanted to create a page with a few input fields and a few submit buttons . Each different submit button clicked will pass different parameters to another page. Example there are name, age and gender fields with 3 submit buttons assigned to each of them. When i click submit button for name, only the parameter of name will be passed. Or are there a different way to accomplish this.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

You can't use different form tags unless the form fields are distinct. You can have each button call a javascript function which sets a different form action and then submits the page:

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Yeah you can have multiple form tags, they just can't be nested within each other.
Also, only the fields defined within each form block will be submitted the "action" URL specified.
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Thanks for the quick reply guys.
Now I have a drop down box named groupings and I want this particular parameter value to be passed for whatever submit button clicked. Example I click the submit button for name and it also pass the groupings parameter. I click the age submit button and groupings parameter is passed and so on.
Can I achieve this in html or do I have to put the drop down groupings box for each and every form tags in my html so that it got passed. If I do this I am afraid there is redundancy.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
you can use javascript to take that one filed and apply it to hidden elements located in the other form fields...
michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Dear Eric,
May I know how to do your suggestion using javascript. I tried using jsp but it seems unable to pass value.
I put this in other form tags
<input name="groupselc" type="hidden" value=<%= nameg%>>
with nameg being the name of the drop down box.
I did not put the drop down box in form tag though. Do I need to put it in a form tag with another name. Thanks
wood burning stoves
subject: Many form tags in html
It's not a secret anymore!