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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to call sub from html link or button 1

Status
Not open for further replies.

ilpadrino

MIS
Feb 14, 2001
416
US
I'm a beginner trying to use perl to display web content. I'd like to call a subroutine from a button or link. Can anyone help me with the syntax?

Here's an example of what I'm doing wrong:

print &quot;<a href=&quot;, &sub(192.168.1.1), &quot;>Click here</a>&quot;

The &sub() takes the argument, determines and stores its status as a global string.

Thanks in advance.
 
Keep in mind that perl is a server side language, not client side(like javascript). This means to get perl to run you have to click off the webpage or submit a form (both linked to the CGI). The CGI handles this request and then returns a result as a NEW webpage.

So, there are no 'global strings' inside a webpage.

What you want is Javascript I think, check the javascript forum. This is easily accomplished in that language.


A HREF=&quot;javascript:?(192.168.1.1)&quot;

then you have a javascript block that looks like this
---
var GLOBAL_STRING ;

function C(input) {
GLOBAL_STRING=input;
}
---
I didnt test this, its only conceptual. The JS forum or a tutorial webpage is your best bet.
 
thanks siberian. your point is exactly what i failed to realize.
 
He is wrong... I can do anything (almost) clientside that i can do serverside and soon i will develop (no need to process HTA with Perlscript and vbscript) which is like active client pages.
 
Sorry about not reading into you question...

here you go...

<body id=&quot;Bel&quot;>
<div id=&quot;Response&quot;></div>
<h2>Test of a PerlScript function being called from VBScript</h2>
<p>
<input type=&quot;text&quot; id=&quot;PipeCreate&quot; value=&quot;&quot;>
<input type=&quot;button&quot; onclick=&quot;namePipe, PipeCreate&quot; value=&quot;Create Pipe&quot;><br>
<input id=&quot;WriteThis&quot; type=&quot;text&quot; size=&quot;15&quot; value=&quot;&quot;>
<input type=&quot;button&quot; onclick=&quot;WriteToPipe&quot; value=&quot;Write To Created Pipe&quot;>
<input type=&quot;button&quot; onclick=&quot;ReadFromPipe&quot; value=&quot;Read Pipe&quot;>
</p>
<input type=&quot;button&quot; onclick=&quot;Discon&quot; value=&quot;Disconnect Pipe!!&quot;>
<form method=&quot;POST&quot; action=&quot;&quot; onsubmit=&quot;javascript:return false&quot;>
<p><input type=&quot;button&quot; value=&quot;Close&quot; onclick=&quot;javascript:self.close();&quot;></p>
</form>
<p>
</p>
<script language=&quot;PerlScript&quot;>
use Win32::pipe;
sub namePipe {
$pipe = $window->document->getElementByID(PipeCreate)->value;
}
sub WriteToPipe {
$WhatToWrite= $window->document->getElementByID(WriteThis)->value;
$OurPipe = new Win32::pipe(&quot;\\\\.\\Pipe\\$pipe&quot;)|| die $window->alert(&quot;Can't Create Named $pipe\n&quot;);
my $Writer = $OurPipe->Write(&quot;$WhatToWrite&quot;);
}
sub ReadFromPipe {
$OurPipe = new Win32::pipe(&quot;\\\\.\\Pipe\\$pipe&quot;)|| die $window->alert(&quot;Can't Create Named $pipe\n&quot;);
$Data = $OurPipe->Read();
$DatRetVal =&quot;This Is The Data $Data&quot;;
$window->alert($DatRetVal);
}
sub PipeCreate {
$OurPipe = new Win32::pipe(&quot;$pipe&quot;)|| die $window->alert(&quot;Can't Create Named $OurPipe\n&quot;);
}
sub Discon {
$OurPipe = new Win32::pipe(&quot;\\\\.\\Pipe\\$pipe&quot;)|| die $window->alert(&quot;Can't Create Named $OurPipe err1 \n&quot;);
$OurPipe->Close()|| die $window->alert(&quot;Can't Create Named $pipe err2\n&quot;);
$OurPipe->Disconnect()|| die $window->alert(&quot;Can't Create Named $pipe err3 \n&quot;);
}
sub sayHello {
# This function takes two parameters, creates a string
# from the parameters, and returns the string.

# get the two parameters into local variables
my ($strName, $strTime) = @_;
#now, create the return string.
$strRetVal=&quot;Hello $strName. The time is $strTime.&quot;;

# Return the string
$strRetVal;
}
</script>
<Script language=&quot;vbscript&quot;>

strOutput=sayHello(&quot;Visitor&quot;,Now & &quot;&quot;)
Response.innerText= strOutput & &quot; &quot;
</script>
<!-- Insert HTML here -->
</body>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top