lev has asked for the wisdom of the Perl Monks concerning the following question:

Hello friends,
My program for filing and manipulating commands interfaced to a database persists with a curious, but disrupting bug. I was able to confine the problem to a small, simple script that includes a (submit) button to activate the program. The default value of a textarea is then assign to a
variable ( param('textarea name')) which is in turn printed below on the web page.
Results?: Starting with a cleared textarea, a first click of the button brings the default command to the textarea. A second click of the button replaces the last two characters of the previous command with"Pr".
For example: SELECT * FROM Departments
becomes........SELECT * FROM DepartmenPr
From where does this "Pr" bug originate and how is it entering the textarea?
This portion of my program is below:
----------------------------------
#!/usr/bin/perl -w use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); use strict; my $query = new CGI; my $JSCRIPT=<<EOF; function sub_dispatcher() { document.sql_tool.submit();//document.sql_tool.mysql_Query = passit; } EOF ; #SETTING UP A FORM FOR INPUT: print $query->header(); print $query->start_html(-title => 'Selection ', -BGCOLOR=>'lavender', -script=>$JSCRIPT); print $query->startform(-name=>'sql_tool'); print $query->textarea(-name=>'mysql_Query', -default=>'SELECT * FROM Departments', -id=>'textarea1', -rows=>14, -cols=>70),p; # -size=>90),p; print $query->button(-name=>'save2file', -value=>'execute write-in (above)', -onClick=>"sub_dispatcher()"),p; print $query->endform(), hr; #------------------------------------------------------ #VARIABLES: my $query_nw = $query->param('mysql_Query'); print "from textarea: $query_nw",p;

Thank you.

Replies are listed 'Best First'.
Re: Curious Bug Entering Textarea
by Your Mother (Archbishop) on Jan 25, 2011 at 17:47 UTC

    I don't think there is anything in your example that could cause that...

    On a sidenote, your CGI style could be improved. You import functions with :standard and then use the OO interface. Do one or the other. I prefer the functions unless you need to pass the CGI object around code. Here is a revamp of your code with a security and JS printing fix. Never send unescaped user input back to the browser. Paragraphs do not separate content, they encapsulate it. And please, please, please use CSS instead of things like -BGCOLOR=>'lavender'.

    use warnings; use strict; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser ); use HTML::Entities qw( encode_entities ); my $js = <<"EOF"; function sub_dispatcher() { document.sql_tool.submit(); } EOF print header(), start_html(-title => 'Selection ', -script => [ $js ] ), startform(-name => 'sql_tool'), p( textarea(-name => 'sql', -default => 'SELECT * FROM Departments', -id => 'textarea1', -rows => 14, -cols => 70), ), p( button(-name => 'save2file', -value => 'execute write-in (above)', -onClick => "sub_dispatcher()"), ), endform(), hr(), ; my $sql = param('sql'); print h3("From textarea: "), pre( encode_entities($sql) || "n/a" ), ;
Re: Curious Bug Entering Textarea
by ahmad (Hermit) on Jan 25, 2011 at 17:34 UTC

    It works fine over here

    No Pr in the output.