planetiowa
asked on
How do I populate form data from a data file when a page is loaded
I browsed around a little to try to find an answer to this but had no luck. I'm creating a page containing text input data that I would like to populate with data read in from a file when the page is loaded. For example:
NAME1:
ADDRESS1:
NAME2:
ADDRESS2:
I have a Perl script that reads and processes the data file but how do I get that data back to the form so that I can update the text boxes?
Thanks
NAME1:
ADDRESS1:
NAME2:
ADDRESS2:
I have a Perl script that reads and processes the data file but how do I get that data back to the form so that I can update the text boxes?
Thanks
ASKER
So based on your response, if I execute my script with a onload command in my HTML, does this mean that any variables declared in the script (such as $data) will be available to the HTML page?
My Perl script is just in bits and pieces but I can clean it up and list it if that helps.
My Perl script is just in bits and pieces but I can clean it up and list it if that helps.
ASKER
I was trying to play around a little more to try to get it to work. In the following snippet, I execute a perl script when the page is loaded (the syntax is based on an example I found on the web). One problem I'm running into with this though is that it doesn't seem to return from the Perl script (I never see the "Hello this is the main page" message). I did confirm that my Perl script runs because it prints out its result.
<html>
<head>
<title></title>
<script language="javascript"><!--
function runcgi(){
window.location.href='/cgi -bin/tourn test.pl';
}
// -->
</script>
</head>
<body>
<script type="text/javascript" language="javascript"> onload = runcgi()</script>
<p> Hello this is the main page. <p>
<input type="text" name="NAME1" value="$data" />
</body>
</html>
-------------------------- -------
PERL SCRIPT:
#!/usr/bin/perl
use CGI ':standard';
print "Content-type: text/html\n\n";
$data = "My Name";
print "HELLO - END OF SCRIPT\n";
<html>
<head>
<title></title>
<script language="javascript"><!--
function runcgi(){
window.location.href='/cgi
}
// -->
</script>
</head>
<body>
<script type="text/javascript" language="javascript"> onload = runcgi()</script>
<p> Hello this is the main page. <p>
<input type="text" name="NAME1" value="$data" />
</body>
</html>
--------------------------
PERL SCRIPT:
#!/usr/bin/perl
use CGI ':standard';
print "Content-type: text/html\n\n";
$data = "My Name";
print "HELLO - END OF SCRIPT\n";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, I left an extra end_html in the if( param() ){ condition.
ASKER
Thanks, I'll give this a try when I get off work. One question though - where does this fit in in the example I showed? Does this replace the "tourntest.pl" PERL script that is called when the page is loaded or is this called and executed in some other way altogether?
If you need more, it might help if you show us your Perl script.