Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript code to perl

Posted on 2002-06-05
6
Medium Priority
?
272 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 150 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
Independent Software Vendors: 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

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 …
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…
Six Sigma Control Plans

927 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