Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Question on HTML Form Elements

Reply
Thread Tools

Question on HTML Form Elements

 
 
amerar@iwc.net
Guest
Posts: n/a
 
      01-10-2006
Hi All,

I've written a Perl/CGI program to read a form and save its data. The
customer wants to be able to edit the data also. So, I wrote that code
also......

However, many of the items on the page are check boxes, radio buttons
and combo boxes.

When printing the form to the screen, how do I place the previously
saved value of a variable into the field?

So, if the box was checked previously, I want to print the form with
the box checked, same for radio buttons, and I'd like the element
selected from the combo box to be the new default.....

Thanks.

Arthur

 
Reply With Quote
 
 
 
 
Brian Wakem
Guest
Posts: n/a
 
      01-10-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:

> Hi All,
>
> I've written a Perl/CGI program to read a form and save its data. The
> customer wants to be able to edit the data also. So, I wrote that code
> also......
>
> However, many of the items on the page are check boxes, radio buttons
> and combo boxes.
>
> When printing the form to the screen, how do I place the previously
> saved value of a variable into the field?
>
> So, if the box was checked previously, I want to print the form with
> the box checked, same for radio buttons, and I'd like the element
> selected from the combo box to be the new default.....



This in not a perl question as it related only to HTML. You may be
generating the HTML output with perl, but the output would be the same
whatever language you were using.


--
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png
 
Reply With Quote
 
 
 
 
Eric
Guest
Posts: n/a
 
      01-10-2006
(E-Mail Removed) wrote:
> Hi All,
>
> I've written a Perl/CGI program to read a form and save its data. The
> customer wants to be able to edit the data also. So, I wrote that code
> also......
>
> However, many of the items on the page are check boxes, radio buttons
> and combo boxes.
>
> When printing the form to the screen, how do I place the previously
> saved value of a variable into the field?
>
> So, if the box was checked previously, I want to print the form with
> the box checked, same for radio buttons, and I'd like the element
> selected from the combo box to be the new default.....
>
> Thanks.
>
> Arthur


Assuming that you are generating the HTML output, you could do
something like the following (snippet):

use strict;
use warnings;
use CGI;
my $q = new CGI;
my $checkbox_status = defined($q->param('checkbox1')) ? "checked" : "";

my $html = qq~
<form>
<input type="checkbox" name="checkbox1" $checkbox_status />
<input type="submit" value="Go" />
</form>~;

print header;
print $html;

The point being that you can add a variable in your HTML
($checkbox_status) and if it is selected when it is submitted, your
script will recognize it and place the correct HTML syntax in the
output. You'd obviously have a lot more logic and code around this, but
it should be a good example.

-Eric

 
Reply With Quote
 
J. Gleixner
Guest
Posts: n/a
 
      01-10-2006
Eric wrote:
> (E-Mail Removed) wrote:
>
>>Hi All,
>>
>>I've written a Perl/CGI program to read a form and save its data. The
>>customer wants to be able to edit the data also. So, I wrote that code
>>also......
>>
>>However, many of the items on the page are check boxes, radio buttons
>>and combo boxes.
>>
>>When printing the form to the screen, how do I place the previously
>>saved value of a variable into the field?
>>
>>So, if the box was checked previously, I want to print the form with
>>the box checked, same for radio buttons, and I'd like the element
>>selected from the combo box to be the new default.....
>>
>>Thanks.
>>
>>Arthur

>
>
> Assuming that you are generating the HTML output, you could do
> something like the following (snippet):
>
> use strict;
> use warnings;
> use CGI;
> my $q = new CGI;
> my $checkbox_status = defined($q->param('checkbox1')) ? "checked" : "";
>
> my $html = qq~
> <form>
> <input type="checkbox" name="checkbox1" $checkbox_status />
> <input type="submit" value="Go" />
> </form>~;
>
> print header;
> print $html;
>
> The point being that you can add a variable in your HTML
> ($checkbox_status) and if it is selected when it is submitted, your
> script will recognize it and place the correct HTML syntax in the
> output. You'd obviously have a lot more logic and code around this, but
> it should be a good example.


As Tim mentioned, provided the OP is using CGI, that's the default. No
need to go through all of that.

use CGI qw(:standard);

print header,
start_html,
start_form,
"Some Label: ", checkbox_group(-name=>'words',
-values => ['eenie','meenie','minie','moe'],
- defaults => ['eenie','minie']), p,
submit,
end_form,
end_html;


Set it, submit it, and the next form will have the elements selected.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newb: recurse over elements children and disable all form elements SteveKlett@gmail.com Javascript 4 09-20-2006 07:42 AM
When JavaScript is disabled, do not display HTML form and form elements patricksabourin@hotmail.com Javascript 5 08-10-2006 05:32 AM
struts indexed form elements not getting into form bean apaeth@fortdearborn.com Java 1 01-07-2006 09:29 PM
Does form.disable work on hidden text form elements? Mark Hannon Javascript 3 09-02-2004 11:37 PM
File uploading from a form with textbox form elements Andy Johns ASP .Net 2 03-02-2004 06:21 AM



Advertisments