School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,354 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,920 people online right now. Registration is fast and FREE... Join Now!




how to call a cgi perl program fro onclick event of a button in html

 

how to call a cgi perl program fro onclick event of a button in html

anusha_dixit

21 Jun, 2009 - 09:08 PM
Post #1

New D.I.C Head
*

Joined: 2 May, 2009
Posts: 3

i have made a cgi perl program which takes the a sequence and compare it with the other in database...it works well in command prompt but when i link it with html page to accept the sequence through html and print the result in html....when i click the button it opens a window asking"do you want to open or save the program" but didnt run it!!

the html code is
CODE

<HTML>
<HEAD>
    <TITLE></TITLE>
</HEAD>
<script>

</script>

<BODY>
<FORM Action = "c:/perl/bin/p1.pl" Method="POST">

  enter the sequence-<input type="text" name="t1" size=100><br>

<input type="Submit" value="submit" onClick="p1.pl">
</form>

</BODY>
</HTML>

and perl script to get the value from html is as follows:-
CODE

#!/usr/bin/perl.exe
require "cgi-lib.pl";
use CGI qw(:standard);

print "Content-type: text/html\n\n";
&PrintHeader;
&ReadParse;
$seq2=$in{'t1'};

please tell me how to do it!!

This post has been edited by anusha_dixit: 21 Jun, 2009 - 09:15 PM

User is offlineProfile CardPM
+Quote Post


anusha_dixit

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

21 Jun, 2009 - 09:08 PM
Post #2

New D.I.C Head
*

Joined: 2 May, 2009
Posts: 3

i have made a cgi perl program which takes the a sequence and compare it with the other in database...it works well in command prompt but when i link it with html page to accept the sequence through html and print the result in html....when i click the button it opens a window asking"do you want to open or save the program" but didnt run it!!

the html code is
CODE

<HTML>
<HEAD>
    <TITLE></TITLE>
</HEAD>
<script>

</script>

<BODY>
<FORM Action = "c:/perl/bin/p1.pl" Method="POST">

  enter the sequence-<input type="text" name="t1" size=100><br>

<input type="Submit" value="submit" onClick="p1.pl">
</form>

</BODY>
</HTML>

and perl script to get the value from html is as follows:-
CODE

#!/usr/bin/perl.exe
require "cgi-lib.pl";
use CGI qw(:standard);

print "Content-type: text/html\n\n";
&PrintHeader;
&ReadParse;
$seq2=$in{'t1'};

please tell me how to do it!!

This post has been edited by anusha_dixit: 21 Jun, 2009 - 09:15 PM
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

21 Jun, 2009 - 09:27 PM
Post #3

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,711



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Topics merged, please don't create duplicates :
User is offlineProfile CardPM
+Quote Post

KevinADC

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

21 Jun, 2009 - 09:57 PM
Post #4

D.I.C Regular
Group Icon

Joined: 23 Jan, 2007
Posts: 401



Thanked: 25 times
Dream Kudos: 50
My Contributions
A CGI script runs from an HTTP server, not your local computer, although the HTTP server can be installed on your local computer and you can connect to it from localhost. You need to install a server like Apache and then configure it to run CGI script. Use Goggle to find some tutorials to help you.
User is offlineProfile CardPM
+Quote Post

dsherohman

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

22 Jun, 2009 - 04:04 AM
Post #5

D.I.C Head
**

Joined: 29 Mar, 2009
Posts: 184



Thanked: 35 times
My Contributions
QUOTE(anusha_dixit @ 22 Jun, 2009 - 05:08 AM) *

when i click the button it opens a window asking"do you want to open or save the program" but didnt run it!!


Your web server is not configured to recognize the script as executable and execute it, so it's sending you the literal content of the document, just like it would for a normal static document.

For Apache, this is controlled by the "ScriptAlias" (to run code within a specific path, such as /cgi-bin/) or AddHandler (to run code with a specific filename extension, such as .cgi) directives. The directory containing the CGI script will also need to have the ExecCGI option turned on (using the "Options" directive) or else you'll get a "permission denied" error when you try to run it.
User is offlineProfile CardPM
+Quote Post

KevinADC

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

22 Jun, 2009 - 06:28 PM
Post #6

D.I.C Regular
Group Icon

Joined: 23 Jan, 2007
Posts: 401



Thanked: 25 times
Dream Kudos: 50
My Contributions
Dave,

I don't think he has gotten as far as the server install yet :

CODE
<FORM Action = "c:/perl/bin/p1.pl" Method="POST">


The action is pointing directly to a perl script.

This post has been edited by KevinADC: 22 Jun, 2009 - 06:29 PM
User is offlineProfile CardPM
+Quote Post

dsherohman

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

23 Jun, 2009 - 04:39 AM
Post #7

D.I.C Head
**

Joined: 29 Mar, 2009
Posts: 184



Thanked: 35 times
My Contributions
QUOTE(KevinADC @ 23 Jun, 2009 - 02:28 AM) *

I don't think he has gotten as far as the server install yet :

CODE
<FORM Action = "c:/perl/bin/p1.pl" Method="POST">


The action is pointing directly to a perl script.

Ah, good catch. I assumed an unrecognized Content-Type header since he gets the "do you want to open or save?" prompt, but missed that the POST was going to a path on C: instead of a URL.
User is offlineProfile CardPM
+Quote Post

chorny_cpan

RE: How To Call A Cgi Perl Program Fro Onclick Event Of A Button In Html

25 Jun, 2009 - 02:58 AM
Post #8

New D.I.C Head
Group Icon

Joined: 13 May, 2009
Posts: 35


Dream Kudos: 25
My Contributions
1. Do use "require "cgi-lib.pl";".

2. Read Ovid's CGI Course.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 07:15PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month