File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing values from a form inside a form?

 
Brian Swingle
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, what i'm doing is i have one form that encapsultes an unknown quantity of smaller forms depending on the number being passed into "quan". Now my question is can the next servlet that the Main form is being submited too see the fields inside of the smaller forms? Sorry about cutting off the Main form close tag and the submit button.

out.println ("<FORM method='POST' action='http://localhost:8080/servlet/htmlser2'");
out.println ("name = 'hdfrm' >");
for (int i = 1; i < quan; i++)
{
System.out.println("" + i + "");
out.println("<Form name = " + i + ">");
out.println(""+ i +") <input type = text name = Question" + i + "></input><br>");
out.println("<input type = radio name = Answer" + i + "></input> <input Type = checkbox name =Possible" + i + "-1 ></input> <input type = text name =PossibleText" + i + "-1></input>");
out.println("<br><input type = radio name = Answer" + i + "></input> <input Type = checkbox name =Possible" + i + "-2></input> <input type = text name =PossibleText" + i + "-2></input>");
out.println("<br><input type = radio name = Answer" + i + "></input> <input Type = checkbox name =Possible" + i + "-3></input> <input type = text name =PossibleText" + i + "-3></input>");
out.println("<br><input type = radio name = Answer" + i + "></input> <input Type = checkbox name =Possible" + i + "-4></input> <input type = text name =PossibleText" + i + "-4></input>");
out.println("</form>");
}
System.out.println("After loop");
out.println ("<table>");
Any ideas would be greatly appreciated.
Thanks Brian
 
David Hibbs
Ranch Hand
Posts: 374
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would you want a Form inside a Form?
It's not valid anyway.
"A form can contain text and markup (paragraphs, lists, etc.) in addition to form controls."
Visit the HTML spec for forms at
http://www.w3.org/TR/html4/interact/forms.html#h-17.1
[ February 13, 2003: Message edited by: David Hibbs ]
 
Brian Swingle
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understand what your saying and i agree. But the reason why i'm using a form inside a form is becasue i need the radio buttons for each sub form to be mutualy exclusive per iteration of the loop. what this is doing is printing out A test question form to fill out every time the loop iterates. Now the radio buttons are to select the correct answer and have to be mutualy exclusive per question. Is there another way to accomplish this without using a form inside a form?
Thanks
Brian
 
Frank Carver
Sheriff
Posts: 6920
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can still only have one level of form. What everyone else does is to encode something about the iterated item (the value you use as a form name, for example) into the names of the repeated items. For example:

Does that make sense ?
 
Brian Swingle
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok,
I'm following you but that doesn't solve the problem with the radio buttons having to be mutualy exclusive. If i remove the sub forms the radio buttons even being named different in sets of four doesn't allow them to be mutualy exclusive. If i select one all the rest on the page unselect. Thats my problem. maybe i'll just have to use check boxes with some kind of javascript validation.
Thanks,
Brian
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64196
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not so fast...
If you name the radio buttons in each group using the same name, and give each a different value (so you know which one was checked), you will get the behavior you describe without needless hackery.
Load the following page into your browser:

and you will see that a, b, and c belong to one radio group whihc acts independently of the group composed of d, e, and f.
hth,
bear
P.S. For any further discussion I suggest this be moved to the HTML forum.
 
Brian Swingle
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damn,
Bear is good.
Thanks man i worked like a charm. Oh and just for documentation purposes if you put the radio buttons in a table it will invoke the same behavior. Found that out by mistake. Any way Big thanks to all and Bear.
Thanks,
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic