Here's two ways* I would consider (there are pros and cons to each):

1. HTML and Javascript (fast, client-side, but 10%± have JS turned off):

First number: <input type="text" id="num1" /> Second number: <input type="text" id="num2" /> Your answer: <input type="text" id="answer" /> Add them: <input type="button" value="Add" onclick="addthem();" />

or HTML for CGI handling, change last lines to:

Your answer: <input type="text" id="answer" value="<tmpl_var answer>" /> <input type="submit" value="Add" />

Javascript:

function addthem() { var num1 = document.getElementById("num1"); var num2 = document.getElementById("num2"); var answer = num1 + num2; document.getElementById("answer").value = answer; }

2. CGI and HTML::Template (doesn't require JS, but does require a module and a round robin to the server):

use HTML::Template; use CGI; my $query = new CGI; my $num1 = $query->param('num1'); my $num2 = $query->param('num2'); my $template = HTML::Template -> new(filename => "addnumbers.tmpl"); $template->param( answer => $num1 + $num2 ) print "Content-type: text/html\n\n"; print $template->output();
*all code is untested

—Brad
"Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton

In reply to Re: How to get data from a web page. by bradcathey
in thread How to get data from a web page. by munu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.