jjinno
04-01-2005, 10:26 AM
I am using Perl to write HTML. I have the use CGI line...blah blah blah, with all my tags supported and such.
My problem is not that it doesnt write. It is that it writes too much, like when I go to do something like the following code, I get a weird occurrance of //<![CDATA[ //]]> around my generated JavaScript. Why? Is it my semi-colons?
sub javaCheck() {
# Make a variable to hold the JavaScript
$JS = qq@function validateMe(){\n@;
$mylen = @listoproducts;
for ($k=0; $k<$mylen; $k++) {
$JS = $JS . qq@if(document.myform.$listoproducts[$k].value == "") {\n@;
$JS = $JS . qq@document.myform.$listoproducts[$k].value == "0";\n@;
$JS = $JS . qq@} else@;
}
$JS = $JS . qq@if(document.myform.uname.value == "") {\n
alert("You forgot to enter your name.");
return false;
\n}else@;
$JS = $JS . qq@if(document.myform.address.value == "") {\n
alert("You forgot to enter your Address.");
return false;
\n}else@;
$JS = $JS . qq@if(document.myform.zip.value == "") {\n
alert("You forgot to enter your City/State/Zip.");
return false;
\n}@;
$JS = $JS . qq@}\n@
}
And here is what it generated:
//<![CDATA[
function validateMe(){
if(document.myform.type1.value == "") {
document.myform.type1.value == "0";
} elseif(document.myform.type2.value == "") {
document.myform.type2.value == "0";
} elseif(document.myform.type3.value == "") {
document.myform.type3.value == "0";
} elseif(document.myform.type4.value == "") {
document.myform.type4.value == "0";
} elseif(document.myform.type5.value == "") {
document.myform.type5.value == "0";
} elseif(document.myform.name.value == "") {
alert("You forgot to enter your name.");
return false;
}elseif(document.myform.address.value == "") {
alert("You forgot to enter your Address.");
return false;
}elseif(document.myform.zip.value == "") {
alert("You forgot to enter your City/State/Zip.");
return false;
}}
//]]>
My problem is not that it doesnt write. It is that it writes too much, like when I go to do something like the following code, I get a weird occurrance of //<![CDATA[ //]]> around my generated JavaScript. Why? Is it my semi-colons?
sub javaCheck() {
# Make a variable to hold the JavaScript
$JS = qq@function validateMe(){\n@;
$mylen = @listoproducts;
for ($k=0; $k<$mylen; $k++) {
$JS = $JS . qq@if(document.myform.$listoproducts[$k].value == "") {\n@;
$JS = $JS . qq@document.myform.$listoproducts[$k].value == "0";\n@;
$JS = $JS . qq@} else@;
}
$JS = $JS . qq@if(document.myform.uname.value == "") {\n
alert("You forgot to enter your name.");
return false;
\n}else@;
$JS = $JS . qq@if(document.myform.address.value == "") {\n
alert("You forgot to enter your Address.");
return false;
\n}else@;
$JS = $JS . qq@if(document.myform.zip.value == "") {\n
alert("You forgot to enter your City/State/Zip.");
return false;
\n}@;
$JS = $JS . qq@}\n@
}
And here is what it generated:
//<![CDATA[
function validateMe(){
if(document.myform.type1.value == "") {
document.myform.type1.value == "0";
} elseif(document.myform.type2.value == "") {
document.myform.type2.value == "0";
} elseif(document.myform.type3.value == "") {
document.myform.type3.value == "0";
} elseif(document.myform.type4.value == "") {
document.myform.type4.value == "0";
} elseif(document.myform.type5.value == "") {
document.myform.type5.value == "0";
} elseif(document.myform.name.value == "") {
alert("You forgot to enter your name.");
return false;
}elseif(document.myform.address.value == "") {
alert("You forgot to enter your Address.");
return false;
}elseif(document.myform.zip.value == "") {
alert("You forgot to enter your City/State/Zip.");
return false;
}}
//]]>