Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do I populate form data from a data file when a page is loaded

Posted on 2004-10-12
6
Medium Priority
?
194 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:planetiowa
[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
  • 3
  • 3
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 12294716
<input type="text" name="NAME1" value="$data" />

If you need more, it might help if you show us your Perl script.
0
 

Author Comment

by:planetiowa
ID: 12294762
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.
 
0
 

Author Comment

by:planetiowa
ID: 12294874
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/tourntest.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";
0
Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 12295183
#!/usr/bin/perl
use CGI ':standard';
print header;
print start_html(-script=>"
function runcgi(){
window.location.href='/cgi-bin/tourntest.pl';
}");

if( param() ){
     print "Your name is",em(param('NAME1')),p;
     print end_html;
}else{
    $data = "My Name";
    print "<p> Hello this is the main page. <p>\n";
    print start_form;
    print qq(<input type="text" name="NAME1" value="$data" />\n);
    print end_form;
}
print "HELLO - END OF SCRIPT\n";
print end_html;
0
 
LVL 84

Expert Comment

by:ozo
ID: 12295198
Sorry, I left an extra end_html in the if( param() ){ condition.
0
 

Author Comment

by:planetiowa
ID: 12298312
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?
0

Featured Post

CHALLENGE LAB: Troubleshooting Connectivity Issues

Goal: Fix the connectivity issue in the lab's AWS environment so that you can SSH into the provided EC2 instance.  

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to count occurrences of each item in an array.

661 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