By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,174 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

embedding javascript using html into perl script

100+
P: 236
Hi All,

I am creating the perl script using html form(with embedded javascript inside).

When using this html form with javascript alone, it works where the form validation will pop up javascript windows to say the field is not keyed into properly. However, when i convert this html(with javascript inside) into perl script, the perl script did not validate when i keyed incorrect data in the form and it straight away executed perl script without using the java script validation.

The code is below.



Thanks and Best Rgds,
Andrew



Perl script - with html(javascript inside also)

Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl.exe -w
  2. #!/usr/local/bin/perl
  3.  
  4.  
  5. print "Content-type: text/html\n\n";
  6. print qq%
  7.  
  8. #this portion will be html with javascript alone, except %; at the closing end.
  9. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  10. <html>
  11. <head>
  12. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  13. <title>L&A Fashion</title>
  14. <meta http-equiv="Page-Enter" content="blendTrans(Duration=1)">
  15. <meta name="GENERATOR" content="Created by BlueVoda">
  16. <script language="JavaScript" type="text/javascript">
  17. <!--
  18. function ValidateForm1(theForm)
  19. {
  20. var strFilter = /^[A-Za-z0-9-]*$/;
  21. var chkVal = theForm.Editbox10.value;
  22. if (!strFilter.test(chkVal))
  23. {
  24.    alert("Username must be minimum 6 characters and maximum 30 characters and it should be digits or alphabets");
  25.    theForm.Editbox10.focus();
  26.    return false;
  27. }
  28. if (theForm.Editbox10.value.length < 6)
  29. {
  30.    alert("Username must be minimum 6 characters and maximum 30 characters and it should be digits or alphabets");
  31.    theForm.Editbox10.focus();
  32.    return false;
  33. }
  34. if (theForm.Editbox10.value.length > 30)
  35. {
  36.    alert("Username must be minimum 6 characters and maximum 30 characters and it should be digits or alphabets");
  37.    theForm.Editbox10.focus();
  38.    return false;
  39. }
  40. return true;
  41. }
  42. //-->
  43. </script>
  44. <style type="text/css">
  45. a.style1:link {color: #FF80C0;font-weight: bold;font-style: italic;text-decoration: none;}
  46. a.style1:visited {color: #FF80C0;font-weight: bold;font-style: italic;text-decoration: none;}
  47. a.style1:active {color: #FF80C0;font-weight: bold;font-style: italic;text-decoration: none;}
  48. a.style1:hover {color: #FF80C0;font-weight: bold;font-style: italic;text-decoration: none;}
  49. </style>
  50. <style type="text/css">
  51. img { behavior: url("pngfix.htc"); }
  52. </style>
  53. </head>
  54. <body bgcolor="#FFFFFF" text="#000000">
  55. <div id="bv_Image1" style="overflow:hidden;position:absolute;left:0px;top:0px;z-index:5" align="left">
  56. <img src="bv01016.jpg" id="Image1" alt="" align="top" border="0" style="width:562px;height:915px;"></div>
  57. <div id="bv_Image10" style="overflow:hidden;position:absolute;left:1039px;top:761px;z-index:6" align="left">
  58. <img src="AL__44_.JPG" id="Image10" alt="" align="top" border="0" style="width:112px;height:96px;"></div>
  59. <div id="bv_Text12" style="position:absolute;left:308px;top:144px;width:100px;height:16px;z-index:7" align="center">
  60. &nbsp;</div>
  61. <div id="bv_Image12" style="overflow:hidden;position:absolute;left:562px;top:0px;z-index:8" align="left">
  62. <img src="bv01017.jpg" id="Image12" alt="" align="top" border="0" style="width:644px;height:915px;"></div>
  63. <div id="bv_Text9" style="position:absolute;left:827px;top:493px;width:122px;height:19px;z-index:9" align="center">
  64. &nbsp;</div>
  65. <div id="bv_Shape2" style="position:absolute;left:196px;top:136px;width:555px;height:553px;z-index:10" align="center">
  66. <img src="bv01042.png" id="Shape2" align="top" alt="" title="" border="0" width="555" height="553"></div>
  67. <div id="bv_Shape3" style="position:absolute;left:378px;top:5px;width:201px;height:125px;z-index:11" align="center">
  68. <img src="bv01050.png" id="Shape3" align="top" alt="" title="" border="0" width="201" height="125"></div>
  69. <img src="bv01051.gif" id="Text2" width="131" height="110" align="top" alt="" border="0" style="position:absolute;left:403px;top:16px;width:131px;height:110px;z-index:12">
  70. <div id="bv_Form1" style="position:absolute;left:201px;top:136px;width:541px;height:463px;z-index:13" align="left">
  71. <form name="Form1" method="POST" action="http://127.0.0.1/cgi-bin/acctman2-if.pl" enctype="multipart/form-data" id="Form1" onsubmit="return ValidateForm1('this')">
  72. <div id="bv_Text13" style="position:absolute;left:51px;top:138px;width:153px;height:16px;z-index:0" align="right">
  73. <font style="font-size:13px" color="#388E8E" face="Arial"><b>Username * : </b></font></div>
  74. <input type="submit" id="Button1"" name="Button1" value="Sign Up" style="position:absolute;left:225px;top:417px;width:75px;height:24px;z-index:1">
  75. <div id="bv_Text1" style="position:absolute;left:17px;top:66px;width:508px;height:16px;z-index:2" align="left">
  76. <font style="font-size:13px" color="#800080" face="Arial"><b>Please key in below for Registration Sign Up (* denotes Compulsory)</b></font></div>
  77. <div id="bv_Shape1" style="position:absolute;left:211px;top:9px;width:140px;height:53px;z-index:3" align="center">
  78. <img src="bv01052.png" id="Shape1" align="top" alt="" title="" border="0" width="140" height="53"></div>
  79. <input type="text" id="Editbox10" style="position:absolute;left:211px;top:136px;width:160px;font-family:Courier New;font-size:16px;z-index:4" size="16" name="Username" value="" maxlength="30">
  80.  
  81. </form>
  82. </div>
  83. </body>
  84. </html>%;
  85.  
  86.  
Jul 2 '09 #1
Share this Question
Share on Google+
3 Replies


100+
P: 236
pls advise why onsubmit="return ValidateForm1('this')" did not work in the form validation... The below example worked however...

Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl.exe -w
  2. #!/usr/local/bin/perl
  3.  
  4. my $random_number = int( rand( 10)); 
  5.  
  6. print "Content-type: text/html\n\n";
  7. print qq|
  8.  
  9. <html> 
  10. <head> 
  11. <title>A Random Number</title> 
  12.  
  13. <script language="JavaScript" type="text/javascript">
  14. var myNumber = $random_number; 
  15.  
  16. function display() { 
  17. alert( "Your random number is "+ myNumber); 
  18. </script> 
  19.  
  20. <style> 
  21. .display { padding: 50px; text-align: center; background: lightblue; } 
  22. </style> 
  23.  
  24. </head> 
  25.  
  26. <body> 
  27. <div class="display" onMouseOver="display();">HOVER HERE TO SEE THE NUMBER!</div> 
  28. </body> 
  29.  
  30. </html> |;
  31.  
Jul 2 '09 #2

KevinADC
Expert 2.5K+
P: 4,059
In your first code you have this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. print qq%
  3.  
  4. #this portion will be html with javascript alone, except %; at the closing end.
  5.  

You need to remove the line that starts with # because that is not a comment that is just text inside of a qq string and the % symbol is breaking your code in that line. I don't know if that will make your javascript code work but it should make your perl code work.
Jul 2 '09 #3

100+
P: 236
oh, the # comment was not part of the code. Only my comments... at wits end. Surveyed many websites... still not able... thanks...
Jul 2 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.