Hi Guys, I have been searching google for hours and can't find a solution to this problem so any help will be fantastic.

I'm creating image buttons via a while loop as I need these buttons to be created dynamically because it pulls data from a mysql database. I need these buttons to work independently. So for example, pressing 'button1' will make 'action1' happen.

I have currently set the input name of the image buttons to the names I am pulling from the database using the Perl variable "$unit_name". Inspecting the buttons on the website itself I can see the values are being set to the names I am expecting, and when setting the form method to GET I can see the names in the URL bar.

When you press a button I intend for the form to submit so the name of whichever button has been pressed can be sent through as a parameter. However at the moment the variable "selectedName" receives no data.

Here is where I pull the parameter:
my $selectedName = param('$unit_name');
Here is the while loop I am using to create the buttons:
my $statement2 = "select unit_name from unitNamesTable"; my $sth = $dbh->prepare($statement2); $sth->execute(); while (my @data = $sth->fetchrow_array()) { $unit_name = $data[0]; push(@unitNames, $unit_name); print "<td>$unit_name<br>"; print "<input type=image name='$unit_name' id=$unit_name value='$u +nit_name' alt=airConButton src=../../images/unit.jpg height=100px wid +th=100px onclick=this.form.submit()>"; }
If you need anything else or have any ideas how I can either fix this or go about it in a better way please let me know. Thanks in advance!

In reply to 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.