develooper Front page | perl.beginners | Postings from December 2002

FW: Simple Question

Dan Muey
December 27, 2002 16:24
FW: Simple Question
Message ID:

Are you talking about a form where you type in say '10' in fieed one and '15 in field two and the actual html page changes to say '25' as soon as you type them in without hitting submit?

If so, yes you'll need javascript, and getting it to work is a javascript issue. As far as javascript goes it's no different than html. And as with html if you print improper html it will look funny so it is with printing javascript. If it gets printed wrong then it will be wrong. EG 
Just as  this :
print "<a href=\"\" </A>";
Would print a bad link since there is no closing '>' for the first 'a' tag so 
print "<script> bad javascript here </script>";
Would print out javascript that doesn't work, so I ask again does the javascript /html that you are trying to get the script to print out work in a regular old static .html page?

If it works just how you want it in the .html file above, compare the working code to the script's output and you'll probably find that there are somekind of quotes missing in the perl generated code since sometimes you need to back slash them to have them treated as literal ' and " characters. EG - ...eval(\'theform.num\'+i)...

If you can't get it to work in a regular static .html file then you'll need to get the right html/javascript code that does what you want , then have the script print the same code out.

As far as the browser goes perl will print anything you tell it to but yes the browser will display the html and run javascript how it thinks it should so there is no fool proof way to make it work for every browser exactly the same way. 


-----Original Message-----
From: R. Joseph Newton [] 
Sent: Friday, December 27, 2002 3:44 PM
To: Janfek Esquivel
Subject: Re: Simple Question


If you are moving from a ten-line Javascript routine to perl, do you cgi first on a simple form with two or t\hree fields.  You must learn to crawl before you try to run a marathon.

When you've made a couple simple cgi forms work, and get back to this, here are some preliminary tips:
1)  Dump the lists of variables within your program.  Anything you would name in a pattern like that would be better in an array, probably a two-dimensional on.
2) When you have simplified your program variables to a simple array, use a nested loop to move through the form variables you receiveand assign them to elements of your program array.
3) Give your variables meaningful names.  Data, dato, or d tells you absolutely nothing about what kind of information you are dealing with, and therefore provides no guidelines for evaluating whether your processing makes sense..  It will be much easier to keep track of the process if you are making reference to something concrete.


Janfek Esquivel wrote:

> I have a cgi that gets variables from a form (only numeric) and that
> form is sent to a text file to get the information that I need later. 
> What I'm having problems with is that I need some fields to add 
> themselves and display different totals on the same form when a 
> modification is made to one of those fileds. I used a Javascript and 
> tested it on an html, it works, but it doesn't seem to work on my cgi. 
> Is there something I'm doing wrong, is there something else I can do? 
> Your help will be appreciated. Here is the javascript I'm using and 
> also I attach the cgi. Thanks in advance.
> Janfek Esquivel.
> <script language="JavaScript">
>    <!--
>    var totalBoxes = 11;
>    function updateTotal(theform) {
>         var d1_12 = 0;
>         for (var i = 1; i < totalBoxes + 1; i++) {
>              d1_12 -= eval('theform.num'+i).value;
>         }
>         theform.d1_12.value = -d1_12;
>    }
>    // -->
>    </script>
> _________________________________________________________________
> Add photos to your e-mail with MSN 8. Get 3 months FREE*.
> 7324&DI=7474&SU=
>                                                   -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>                   Name:
>    Type: Zip Compressed Data (application/x-zip-compressed)
>               Encoding: base64
> ----------------------------------------------------------------------
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> --
> To unsubscribe, e-mail:
> For additional commands, e-mail: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About