[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

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

                               
0
boofulls
Asked:
boofulls
1 Solution
 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now