473,699 Members | 2,722 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

embedding javascript using html into perl script

236 New Member
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,

Perl script - with html(javascript inside also)

Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl.exe -w
  2. #!/usr/local/bin/perl
  5. print "Content-type: text/html\n\n";
  6. print qq%
  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="" 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">
  81. </form>
  82. </div>
  83. </body>
  84. </html>%;
Jul 2 '09 #1
3 3904
236 New Member
pls advise why onsubmit="retur n 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
  4. my $random_number = int( rand( 10)); 
  6. print "Content-type: text/html\n\n";
  7. print qq|
  9. <html> 
  10. <head> 
  11. <title>A Random Number</title> 
  13. <script language="JavaScript" type="text/javascript">
  14. var myNumber = $random_number; 
  16. function display() { 
  17. alert( "Your random number is "+ myNumber); 
  18. </script> 
  20. <style> 
  21. .display { padding: 50px; text-align: center; background: lightblue; } 
  22. </style> 
  24. </head> 
  26. <body> 
  27. <div class="display" onMouseOver="display();">HOVER HERE TO SEE THE NUMBER!</div> 
  28. </body> 
  30. </html> |;
Jul 2 '09 #2
4,059 Recognized Expert Specialist
In your first code you have this:

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

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
236 New Member
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

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

Similar topics

by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.