Solved

Javascript code to perl

Posted on 2002-06-05
6
262 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

932 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

12 Experts available now in Live!

Get 1:1 Help Now