Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Passing values from a form inside a form?

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67750
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
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic