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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with displaying Javascript w/ Perl

Status
Not open for further replies.

KChang

Programmer
Joined
Dec 7, 2006
Messages
3
Location
US
Hello, I am having an issue that is driving me nuts and probably has a simple resolution,

I am storing Java script code in a string example

$javaSC pulls code from a database

$javaSC = "<script type="text/javascript">
<!--
xxx
//--></script>

the problem is when displayed for the user to copy it only shos this

<script type="text/javascript">
</script>

this part

<!--
xxx
//-->

is missing.


Please help

Kimberly
 
this is a sample using an input box to demonstrate what I mean

#!/usr/bin/perl -w


@widgetformhead = <<"HTML";
<form method="post">
<textarea name="snippetsource" cols="50" class="required" id="snippet[source]"/>
</textarea>
<input type="submit" class="primaryAction" id="submit-wf_TestForm" value="submit"/>
<input name="entered" type="hidden" value="yes">
</form>
HTML


###get form values

if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'}) {
@getpairs = split(/&/,$ENV{'QUERY_STRING'});
push (@pairs, @getpairs);}
}

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$value =~ tr/+/ /;
$name =~ s/%(..)/pack("C", hex($1))/eg;
$value =~ s/%(..)/pack ("C", hex($1))/eg;
$value =~ s/<!--(.|\n)*-->//g;

if ($in{$name}){$in{$name}.=", $value";}
else{$in{$name} = $value;}}

if ($in{'entered'} ne "yes"){
print "Content-Type: text/html\n\n";
print @widgetformhead;
}
## If the quiz was taken grade it
else
{
print "Content-Type: text/html\n\n";
print $in{'snippetsource'};
}
 
this line removes comments:

Code:
$value =~ s/<!--(.|\n)*-->//g;

If your javascript stuff goes through that it will be zonked. Comment out the above line in your code and retry.

Code:
[COLOR=red]#[/color]$value =~ s/<!--(.|\n)*-->//g;

- Kevin, perl coder unexceptional!
 
Duh I knew it was something stoopid you always make things harder than they are when you are tired thank you very much for looking over this for me.
 
why are you sending javascript code through a form anyway?

- Kevin, perl coder unexceptional!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top