Solved

Javascript code to perl

Posted on 2002-06-05
6
261 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
Comment Utility
#!/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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

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

Author Comment

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

Expert Comment

by:lexxwern
Comment Utility
great, good luck with your programming.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now