Solved

Javascript code to perl

Posted on 2002-06-05
6
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

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…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…

751 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