Hi,
What I meant was like when you submit the form you can have <form action="/cgi-bin/postcode.
Thanks for clarifying.
Cheers!!
Main Topics
Browse All TopicsHI,
I have a HTML form where I need to provide a postcode lookup (via a perl script) before the form is actually submitted and return the results of the perl script back to the form and then the user continues to fill in the remaining fields.
How can I provide a button in the HTML form that calls a perl script for postcode lookup without submitting the form?
One way that I think is to submit the form with all the details until postcode lookup (<input type="submit" value="Postcode Lookup">) and calling the lookup.pl script which regenrated the whole form with all the values that user had filled already filled in and then another submit button to sumbit the complete form.
But I'm not too sure whether using 2 submit buttons is the best way. I was thinking if we can use an "onclick" function on an ordinary button ie <input type="button" value="Postcode Lookup" onclick="a function()">
Can I call the perl script directly from the onclick feature or would I need to call a javascript function in whcih I can call teh perl script??
Any help would be greatly appreciated.
Regards.
THanks for the help here??
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi,
What I meant was like when you submit the form you can have <form action="/cgi-bin/postcode.
Thanks for clarifying.
Cheers!!
it seems like you need... AJAX! :)
Fear not my friend.. u can visit http://www.perljax.us/ and install the module on your server.
The Perl::Ajax module will call any perl functions / subs / outside file without needing to refresh the whole page. the output will be print on any given <div> tags. just like google! :)
Hey Thanks DingDang!!
CAn you share some sample code please?? Below is the simplified version of the form.
<form action="../../cgi-bin/some
<table width="100%" border="0" cellspacing="0" cellpadding="5" bgcolor="CCCC99" align="center">
<tr>
<td class="text"><strong>Foren
<td><input name="forenames" type="text" id="xyz15" size="30" maxlength="100">*</td>
</tr>
<tr>
<td class="text"><strong>Surna
<td><input type="text" name="surname" size="30" maxlength="100">*</td>
</tr>
<tr>
<td class="text"><strong class="text">House Name/Number %]</strong></td>
<td><input name="address_housenumber"
</tr>
<tr>
<td class="text"><strong class="text">Postcode</str
<td><input name="l_postcode" type="text" size="30" maxlength="100">*
<input name="postcode" type="submit" value="Postcode Lookup" class="text"></td>
</tr>
[% IF paf_results %]
<tr>
<td class="text"><strong class="text">[% copy.select_address %]</strong></td>
<td><select name="pafaddress">
[% FOREACH address = paf_results.sort %]
<option value="[% address %]">[% address %]</option>
[% END %]
</td>
</tr>
[% ELSE %]
<!-- Display the normal 5 address fields -->
<!-- Rest of the form continued -->
[% END %
<tr>
<td><input name="button1" type="submit" id="button1" value="Submit"></td>
</tr>
</form>
THaks
here is the working example (my version)
--------------------
#!/usr/bin/perl
use CGI::Carp "fatalsToBrowser"; # Output errors to browser
use CGI qw(:standard); # Saves loads of work
use CGI::Ajax;
$query = new CGI;
sub getform {
my ($frm_val) = shift;
if ($frm_val eq "123456") {
$myoutput =qq~Postcode 123456 Entered!~;
}
elsif ($frm_val eq "456789") {
$myoutput =qq~Postcode 456789 Entered!~;
}
else {
$myoutput =qq~Invalid Postcode entered : $frm_val~;
}
return $myoutput;
}
my $html = <<EOT;
<html>
<head>
<title>PerlJax test</title>
</head>
<html>
<!-- first level form -->
Name : <input type=text id="name" name="name"><br>
Postcode : <input type=text id="postcode" name="postcode"><input type="button" value="Find" onclick="getform(['postcod
(Test value is 123456 and 456789)<br><br>
<!-- second level form -->
<div id="result"></div>
<!-- second level form - END -->
<!-- first level form - END -->
</html>
EOT
my $pjx = new CGI::Ajax('getform' => \&getform);
my $ajaxjs = $pjx->show_javascript();
$pjx->js_encode_function('
print $pjx->build_html($query,"$
----------------------
For more Perl:Ajax related questions / problems, i think you should channel the concern on their website ( http://www.perljax.us/ ) via the forum. As for your question here, i think it has been answered properly :)
typically when one wants to do something like this there are two possible solutions:
1) do the code on the client machine, in JS or Java - works well if not much to do
2) have the initial entry and submit call a CGI on the server that does whatever it needs to do and re-creates the form with the new data.
As to having two submit buttons on a form, yes you can, but I do not think this will do what you want, since pressing either will send the command back to the server.
Tracfone.com is a good example of a site that uses an input of a zip code and re-paints the screen.
The one other technique that you could use, but I think it is not a good idea, would be to have the zip code part in a different frame, without it being obvious that this was the case. Changig the zip there could cause that frame to be re-freshed after procvessing and the resulting re-fresh can of course write into the other frames
Business Accounts
Answer for Membership
by: ravenplPosted on 2006-03-02 at 02:52:47ID: 16083539
> How can I provide a button in the HTML form that calls a perl script for postcode lookup without submitting the form?
So far I know You can't. That's becouse the broser can't execute perl code.
You have to use some client side language like JavaScript.
Or You would have to use Ajax methods for to submit only copy of the form and obtain validation results.