Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is the best way to fill checkboxes based on form input? 1

Status
Not open for further replies.

UnDoug

Programmer
Dec 11, 2002
14
US
Hi,

I have a perl script that creates a web form. The user can then fill in the form (which contains LOTS of checkboxes) and submit the data. I then need the script to display the form again, but this time reflecting the user's input. So if the original form showed a blank for their name and a set of checkboxes for favorite food, I want the script to show the same form, but this time with the user's responses filled in.

I can do it pretty easily, with the text fields, and when I have a checkbox, I know how to have the script write the form with the checkbox "checked" if the checkbox field's value is "on", but I have a LOT of checkboxes, is there some easy way to have my script do what I want without having to break up the HTML I'm writing in a "here" statement with a bunch of perl statements?
 
Code:
sub check_me {
  ($var)=@_;
  if ($var eq 'on') {  #or whatever value you're using
    return " checked ";
  } 
}

...
print "<input type=\"checkbox\" ".check_me ($whatever)." name=\"whatever\" value=\"on"></input>";
...

Something like this? or a variation thereon
Forgive me, i forget what here documents are ...
--Paul

cigless ...
 
Thanks, PaulTEG!

I had done something similar, but your way is a bit more graceful. I learned a couple things from your post, too!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top