Sorry impossiblerobot - i indeed did miss that rather clear requirement. How about a cleaner HTML::Template solution?
use strict; use CGI qw(header); use HTML::Template; my $data = do {local $/; <DATA>}; my $template = HTML::Template->new( scalarref => \$data, ); $template->param( questions => [ { question => 'What is your favorite number?', radio => [ { regular => 'question01', value => 'a', label => 5, }, { regular => 'question01', value => 'b', label => 7, }, { regular => 'question01', value => 'c', label => 13, }, { special => 'question01', value => 'd', label => 'Other', text => 'other', }, ], }, { question => 'Where did you hear about this product?', radio => [ { regular => 'question02', value => 'a', label => 'Friend', }, { special => 'question02', value => 'b', label => 'Magazine', text => 'magname', }, { regular => 'question02', value => 'c', label => 'Brochure', }, { special => 'question02', value => 'd', label => 'Other', text => 'other', }, ], }, ], ); print header, $template->output; __DATA__ <form> <tmpl_loop questions> <p> <tmpl_var question><br/> <tmpl_loop radio> <tmpl_unless special> <input type="radio" name="<tmpl_var regular>" value="<tmpl_va +r value>"/><tmpl_var label><br/> <tmpl_else> <input type="radio" name="<tmpl_var special>" value="<tmpl_va +r value>"/><tmpl_var label> (please specify:) <input type="text" name="<tmpl_var text>"/><br/> </tmpl_unless> </tmpl_loop> </p> </tmpl_loop> <input type="submit"> </form>
Now for the fun part - getting the right values out! You might want to prefix each text box with the letter and call them all 'other'. For example, instead of calling the Magazine textbox 'magname', call it something along the lines of 'b-other' so you can dynamical retrieve it from CGI::param(). This is just off the top of my head (/me winks at BUU), but you get the point. Good luck!

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to (jeffa) 3Re: Creating HTML radio button group with text field by jeffa
in thread Creating HTML radio button group with text field by impossiblerobot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.