Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling a subroutine from HTML

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
0
0
BE
hi,

Is there a way to call a subroutine from html??
like you can define a variable: script.pl?action=this

Can I call a subroutine in some way? script.pl?&sub

but that doesn't seem to work...

Thanks in advance,
Math
 
There ARE ways to call a program from an html page, but not if you want it to return a value to the place it was called from. If all you want to do is call the program to update some stats, for instance, use an IMG tag, and have your program return a 1x1 pixel transparent gif when it is done (with the appropriate content type header). Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
there's no built in way to do what you want, but it should be really easy for you to make a script that reads in the query string and then executes a subroutine named by it. just have a couple conditionals:[tt]
if ($query_string =~ m/function1/) {&function1();}
elsif ($query_string =~ m/fuction2/) {&function2();}
etc...[/tt]

you could even do autoloading stuff, but i doubt you need something that sophisticated. is this what you're looking for? "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
 
well, actually... I'd want to use it for forms...
I have a script that uses a lot of forms... and I was thinking that It would be handy if I could "submit" a form to a subroutine of a script... It would certainly be easier than submitting all the forms to the same script...

something like <form action=&subA methode=POST>

It would also mean that the script doesn't have to be completely reloaded everytime a form is submitted...

math
 
well, you can always add:[tt]
<INPUT TYPE=&quot;hidden&quot; NAME=&quot;subroutine&quot; VALUE=&quot;fuction1&quot;>
[/tt]
to your forms, then check that paramater first off in the script. there's no built in way to, from a page, call a specific function from a perl script. you have to build that yourself. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
If all the subroutines are in the same source code file, it's going to reload the whole script anyway. You can try breaking it into separate source code files, and using a separate form for each subroutine you want to call. Or you can use an onSubmit function to determine which subroutine you want to call and submit the form to the appropriate program yourself. Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
There is a FAQ, faq452-653, in the CGI forum about such things. This sounds like cgi stuff???

;-)


keep the rudder amid ship and beware the odd typo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top