Fellow Monasterians,

While I have seen this addressed indirectly in various nodes, I haven't been able to find anything definitive.

Here's the scenario: a user selects an option from a pulldown menu and submits a form. My script validates the input, finds a problem, and re-outputs the .tmpl page with the error message.

The associate => $query re-populates text boxes, but I have to rely on some hand-rolled code to re-set any dropdowns.

The code consists of: 1) 'onsubmit' Java-the-script to populate a like-number of hidden fields with the indexes of the options selected; 2) then Perl to grab those and pass them back to H::T if necessary (an error is found); and finally, 3) more JS to reset the dropdowns 'onload'ing. Messy, indeed. Question: What is the better, more Perlish, way? Thanks!

ON SUBMIT: <form id="main" action="cgi-bin/script.pl" method="post" onsubmit="rem +ember_indexes()"> <input type="hidden" id="tmpidx" name="tmpidx" value="" /> <input type="hidden" id="styidx" name="styidx" value="" /> function remember_indexes() { var tmpidx = document.getElementById("templatest").selectedIndex; var styidx = document.getElementById("stylest").selectedIndex; document.getElementById("tmpidx").value = tmpidx; document.getElementById("styidx").value = styidx; }</blockquote> ON RETURNING AFTER ERROR IS FOUND: Perl: my $styidx = $query->param('styidx'); my $tmpidx = $query->param('tmpidx'); $template -> param( errormsg => $errormessage, styidx => $styidx, tmpidx => $tmpidx); HTML: function set_dropdowns() { document.getElementById("styles").options[<tmpl_var styidx>].select +ed = true; document.getElementById("templates").options[<tmpl_var tmpidx>].sel +ected = true;} <body onload="set_dropdowns();"> <p><tmpl_var errormsg><p> <select name="templates" id="templates"> <option value="">Select...</option> <option value="23>">Text one</option> <option value="36>">Text two</option> </select>

Update: fixed tags


—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot

In reply to HTML::Template recalling selected dropdown options by bradcathey

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.