RobRobson has asked for the wisdom of the Perl Monks concerning the following question:
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:Here is the while loop I am using to create the buttons:my $selectedName = param('$unit_name');
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!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()>"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing perl variable as input name?
by Corion (Patriarch) on Jul 21, 2016 at 15:30 UTC | |
by RobRobson (Novice) on Jul 21, 2016 at 15:50 UTC | |
by NetWallah (Canon) on Jul 21, 2016 at 16:21 UTC | |
by RobRobson (Novice) on Jul 22, 2016 at 10:04 UTC | |
by NetWallah (Canon) on Jul 22, 2016 at 14:16 UTC | |
|