Solved

Javascript code to perl

Posted on 2002-06-05
6
265 Views
Last Modified: 2010-03-05
I am new to perl and don't have time to study it thoroughly. I have a perl script in hand and a javascript code. I want my javascript code to be translated to perl so i can incorporate it to my perl script.

Here's the javascript source code with html:

<HTML>
<HEAD>
<TITLE>Quick Mage Lookup</TITLE>
<SCRIPT language="javascript">var mageId=1215;</SCRIPT>
<SCRIPT language="javascript">
function attack(type) {
     document.archform.elements["ENEMY"].value=mageId;
     if(document.archform.elements["ENEMY"].value==0) {
          alert("Please select or enter Mage ID before attacking!");
     } else {
          document.archform.elements["TYPE"].value=type;
          document.archform.target="frmInfo";
          document.archform.action="http://arch11.magewar.com/archmage/war2.cgi";
          document.archform.submit();
     }
     return false;
}

</SCRIPT>
<body>
<table>
<tr>
<td onClick="attack('Siege');">Siege</td>
<td onClick="attack('Regular');">Regular</td>
<td onClick="attack('Pillage');">Pillage</td>
</tr>
</table>
</BODY>
</HTML>

I need it badly coz i handle a bunch of archmage players and that code is a very good help.
0
Comment
Question by:lordtaz
  • 4
6 Comments
 
LVL 12

Accepted Solution

by:
lexxwern earned 50 total points
ID: 7056672
#!/usr/bin/perl -w #change this if required

print qq(Content-type: text/html\n\n


<HTML>
<HEAD>
<TITLE>Quick Mage Lookup</TITLE>
<SCRIPT language="javascript">var mageId=1215;</SCRIPT>
<SCRIPT language="javascript">
function attack(type) {
    document.archform.elements["ENEMY"].value=mageId;
    if(document.archform.elements["ENEMY"].value==0) {
         alert("Please select or enter Mage ID before attacking!");
    } else {
         document.archform.elements["TYPE"].value=type;
         document.archform.target="frmInfo";
         document.archform.action="http://arch11.magewar.com/archmage/war2.cgi";
         document.archform.submit();
    }
    return false;
}

</SCRIPT>
<body>
<table>
<tr>
<td onClick="attack('Siege');">Siege</td>
<td onClick="attack('Regular');">Regular</td>
<td onClick="attack('Pillage');">Pillage</td>
</tr>
</table>
</BODY>
</HTML>

);

0
 
LVL 1

Expert Comment

by:GorGor1
ID: 7057538
what lexxwern is telling you is to just use Perl to generate the html code 'on-the-fly'.  There is no 'direct conversion' from Javascript to Perl.  Perl is a different beast than javascript and behaves differently.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7058326
javascript is client side, so when the page loads, js works with the browser.

perl can be used to tell the server what to load on the browser.

so if you want to run that javascript with perl for any reason, that is the way to do it.

remember a perl script can never interact with the browser the way javascript does, but you can have the perl load some javascript which interacts with the browser.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 12

Expert Comment

by:lexxwern
ID: 7058331
GorGor1 i made an assumption that this is what lordtaz wanted.
0
 

Author Comment

by:lordtaz
ID: 7061548
thanks for the info.. i already found the solutions.. :)
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7069167
great, good luck with your programming.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl split by | 2 103
Replace  text in a file 2 114
Log File Creation with Header and Footer 17 130
Able to retrieve only 1 row through email amongst multiple rows 3 58
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question