THere are several issues you need to correct.

First - you need to fix how you fech the param value - at the time the form' s values are being collected, $unit_name does not exist - so you need to do:

my $selectedName = param('unit_name');
Next, you need to create a single hidden field OUTSIDE the loop:
print "<input type='hidden' name='unit_name' value='This gets set via + javascript'>";
Next, your loop should look something like this:
print "<td>\n"; # If you want all buttons in a single TD .. otherw +ise, this could be <tr> while (my @data = $sth->fetchrow_array()) { $unit_name = $data[0]; push(@unitNames, $unit_name); print "$unit_name<br>"; print "<input type='image' name='$unit_name' id='$unit_name' a +lt=airConButton src='../../images/unit.jpg' height='100px' width='100px' onclick='this.form.unit_name.va +lue =\"$unit_name\";this.form.submit()'></input>"; } # Close the TD or TR here..

        "Software interprets lawyers as damage, and routes around them" - Larry Wall


In reply to Re^5: Passing perl variable as input name? by NetWallah
in thread Passing perl variable as input name? by RobRobson

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.