| Author |
Passing values from a form inside a form?
|
Brian Swingle
Greenhorn
Joined: Feb 12, 2003
Posts: 14
|
|
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
Joined: Dec 19, 2002
Posts: 374
|
|
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 ]
|
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
|
 |
Brian Swingle
Greenhorn
Joined: Feb 12, 2003
Posts: 14
|
|
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
Joined: Jan 07, 1999
Posts: 6913
|
|
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 ?
|
A Convergent Visionary ~ Frank's Punchbarrel Blog ~ LinkedIn profile
|
 |
Brian Swingle
Greenhorn
Joined: Feb 12, 2003
Posts: 14
|
|
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
Joined: Jan 10, 2002
Posts: 56233
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Brian Swingle
Greenhorn
Joined: Feb 12, 2003
Posts: 14
|
|
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
|
 |
 |
|
|
subject: Passing values from a form inside a form?
|
|
|