Question

Calling a perl script from the "onclick" function of a button ****URGENT****

Asked by: PCMENIAC

HI,

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.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2006-03-02 at 02:23:43ID21757613
Tags

perl

,

from

,

function

,

onclick

Topic

Perl Programming Language

Participating Experts
4
Points
500
Comments
13

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

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.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

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.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

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.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Dhtml to perl
    I am dynamically reassigning the positions of some graphics on a web page with the mouse but after I am done I would like to be able to send the position coordinates( with a submit button) to a perl script to be stored so that these rearranged pages could be reloaded by calli...
  2. Javascript code to perl
    I am new to perl and don't have time to study it thoroughly. I have a perl script in hand and a javascript code. I want my javascript code to be translated to perl so i can incorporate it to my perl script. Here's the javascript source code with html: <HTML> <HEAD&...
  3. Replacing data with an onClick statement
    Hi: Could one help me with this onClick statement to put on a input form field below? It replaces, for instance, an entered "www.abc.com" by "mail.abc.com". It works. But I need, in the same statement, to also replace a possibly entered "mail.abc.com...
  4. onclick=
    Quick question, onclick="NavTo(http://www.experts-exchange.com)" or onclick="NavTo(../directory/index.asp)" Can either of these to be used? I am trying to get the onclick= to point directly to a site and to different .asp files.... Any advice? Thank...
  5. onclick
    how do i code an onclick to open another page?

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

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.

Join the Community

Answers

 

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.

 

by: PCMENIACPosted on 2006-03-02 at 03:02:28ID: 16083588

Hi,

What I meant was like when you submit the form you can have <form action="/cgi-bin/postcode.pl" method ="post"> to invoke a perl script,  can you do that without submitting the form and just using a plain button or would I have to call a attach JS function to the onclick method of an ordinary button, and in that JS function call upon the perl script.

Thanks for clarifying.

Cheers!!

 

by: PCMENIACPosted on 2006-03-02 at 03:03:22ID: 16083593

Something like this:

<input type="button" value="submit" onClick="process('/cgi-bin/script.cgi?parm1=one')">

but I'm not too sure how to use this properly.

Cheers.

 

by: ravenplPosted on 2006-03-02 at 05:14:03ID: 16084273

In so simple form: no, You cant.
What You can is do a server request and send the data(copy of the form) to be processed by server. Recently it's know as Ajax technique.

 

by: PCMENIACPosted on 2006-03-02 at 06:03:51ID: 16084624

I've heard about it but found it a bit complicated. So, was wondering if there was an easier way.

If not, can you give me some sample code to do this.

Thanks.

 

by: TintinPosted on 2006-03-02 at 13:01:40ID: 16088781

If you want to submit the form in a new window, you can do:

<form method="post" action="/cgi-bin/script.cgi" name="form" target="new" onsubmit="window.open('','form','resizable=1,scrollbars=1,width=600,height=400'
)">

 

by: PCMENIACPosted on 2006-03-03 at 01:39:33ID: 16092781

Hi,

Unfortunately I wld need to get the results of the postcode lookup and then populate the same form with the results.

Can I have 2 submit buttons in 1 form??

THanks.

Parag

 

by: DingDangPosted on 2006-03-03 at 01:55:55ID: 16092837

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! :)

 

by: PCMENIACPosted on 2006-03-03 at 03:08:52ID: 16093125

Hey Thanks DingDang!!

CAn you share some sample code please?? Below is the simplified version of the form.

<form action="../../cgi-bin/some.pl" method="get" name="br_req" onSubmit="return validate(this);">
<table width="100%" border="0" cellspacing="0" cellpadding="5" bgcolor="CCCC99" align="center">
    <tr>                   
         <td class="text"><strong>Forename</strong></td>
         <td><input name="forenames" type="text" id="xyz15" size="30" maxlength="100">*</td>
    </tr>
    <tr>
          <td class="text"><strong>Surname</strong></td>
          <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" type="text" size="30" maxlength="100">*</td>
    </tr>
    <tr>
          <td class="text"><strong class="text">Postcode</strong></td>
          <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

 

by: DingDangPosted on 2006-03-03 at 17:49:03ID: 16100796

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(['postcode'],['result'])"><br>
(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('escape');
print $pjx->build_html($query,"$html");
----------------------

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 :)

 

by: jhurstPosted on 2006-03-06 at 14:54:36ID: 16119589

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

 

by: PCMENIACPosted on 2006-03-13 at 08:00:57ID: 16175109

THanks Jhurst.

I created a submit call which calls the CGI script and then recreate the same form displays the result which are passed over as hidden parameters from CGI to HTML Form.

 

by: jhurstPosted on 2006-03-14 at 15:49:48ID: 16189671

as a matter of interest why a B, not an A - not to look a gift horse in the mouth

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...