printing javascript code in perl

i have this javascript code for the start of my html page

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>


<SCRIPT LANGUAGE="JavaScript">
<!--//
function change(object,text)
{
object.value = object.value + text;

}
//-->
</SCRIPT>

and this

Word: <INPUT TYPE="text" NAME="text1" value="">

<input type="button" value="é" onClick="change(this.form.text1,'é')">
                                                                               
in order to insert special characters into text boxes (also javascript)

my question is how do i print these lines in my perl script?


i tried

print "<html>";

print "<head>";
print "<SCRIPT LANGUAGE=\"JavaScript\">";
print "<!--//";
print "function change(object,text)";
print "{";
print "object.value = object.value + text\;";

print "}";
print "//-->";
print "</SCRIPT>";

print "</HEAD>";

                                   
for the initial code but it wont work.....
anyone know how i should print the initial code and the lines to insert characters into the text box?

thanks

                               
boofullsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mgoergenCommented:
Hi

Here is a part from one of my script this will work fine. Please note that everything is in a line (print 'Kamer = window ....)

print "Content-Type: text/html\n\n" ;
print '<script language="JavaScript">';
print "<!-- \n";
print "function cam(pa) ";
print "{ ";
print 'te="de-anzeige.pl?"+pa;';
print ' Kamera= window.open(te,"tt","toolbar=0,location=0,directories,status=0,menubar=0,scrollbars=1,resizable=1,width=420,height=550"); ';

print "} //--> </script> ";
print "<title>Anzeige Waren</title>";

..
..
..


Hope it helps you
0
boofullsAuthor Commented:
i tried this for the initial code
   

      print header, start_html('set answers');
#print "<html>";

print "<head>";
print '<SCRIPT LANGUAGE="JavaScript">';
print '<!--//';
print 'function change(object,text)';
print '{';
print 'object.value = object.value + text;';

print '}';
print '//-->';
print '</SCRIPT>';

print '</HEAD>';

                                                       
and this in order to add in text into the text box

print "<INPUT TYPE=\"text\" NAME=\"$name\" value=\"$value\" length=\"$length\" m
ax=\"$max\">";
print '<input type="button" value="this text goes into the text box" onClick="change(this.form.text1,'click to insert text')">';                                          

but all i get is a 0 beside the text box and not a little button that should add text into the text box.....

0
guadalupeCommented:
The problem is that you have mixed single quote for the print and the single quotes of the javascript a much easier way is this syntax called a here document:

print <<EOF;
Content-Type: text/html\n\n
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>

<BODY BGCOLOR="#FFFFFF">

</BODY>
</HTML>
EOF

This works well for multiple lines and you dont have to escape (\) single or double quotes and variables will be interpreted!!!! NOTE!!!! You must place the EOF on a line by itself flush with the left marhin with no semicolon after it and with a return (that is to say it cannot be the last line of a file)!!!!

Another good trick for when you just have one line to print but it may be a html snippet mixed with javascript is to use this style of quoting:

qq{<input type="submit" onClick="change(xx,'hello')">};

for example.  The qq means double quotes there is also q for single quotes (but they print variables as if they were literals - in other words no interpretation!!) and the braces {} act as the delimeters or quotes of the string.   You can also use () <> [] or even !! but be carfull not to repeat the same character inside the string without escaping it like this:

qq!Hello\! You.!; #prints Hello! You.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.