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

onClick button to call perl script. 1

Status
Not open for further replies.

swabs

IS-IT--Management
Jul 28, 2003
155
US
My goal is to be able to call a perl script "test.pl" when a user clicks the button. How do I make the appropriate call. Is onClick the correct choice?



<html>
<head>
<script language="javascript">
function forward() {

var InputAmt = inform.input1;
var NewNum = parseInt(InputAmt.value);
document.write("NewNumber ", NewNum);

}





</script>
</head>
<body>
<h1>TEST phone forward change page</h1>
<hr>

Enter the new Telephone #.
<hr>
<form name="inform">
<input type="text" size="2" name="input1"><br>
<input type="button" value="CHANGE"
onClick=`test3.pl`;>
</form>

<hr>
</body>
</html>
 
Just to follow up. I want "test.pl" to run on the server, not on the client.

 
You could use AJAX to run the script and return the results or you submit your form to the page containing the server-side code. Your approach really depends on what the perl script does and how you want it to interact with the form.



It's hard to think outside the box when I'm trapped in a cubicle.
 
I can't get test.pl to run "onClick
 
If you want to submit the form to test.pl for processing, set it up like this:
Code:
<form name="inform" action="test.pl">
<input type="text" size="2" name="input1"><br>
<input type="Submit" value="CHANGE">
</form>

Lee
 
trollacious,
thanks very much for the help.
I have a second question. How can I pass the value "NewNum" from my function forward()to be an argument for my test.pl file? If the value of NewNum = 2182334532 I would like to allow action of the form to be "test.pl 2182334532". Is this possible?

<html>
<head>
<script language="javascript">
function forward() {

var InputAmt = inform.input1;
var NewNum = parseInt(InputAmt.value);
document.write("NewNumber ", NewNum);

}





</script>
</head>
<body>
<h1>TEST phone forward change page</h1>
<hr>

Enter the new Telephone #.
<hr>
<form name="inform" action="test.pl">
<input type="text" size="2" name="input1"><br>
<input type="Submit" value="CHANGE">
</form>

<hr>
</body>
</html>
 
Something like
Code:
function forward()
{
var InputAmt = inform.input1;
var NewNum = parseInt(InputAmt.value);
document.forms['inform'].action += '?' + NewNum;
return true;
}

and

Code:
<form name="inform" action="test.pl" onsubmit="forward();">
[code]

Lee
 
Trollacious,
Thanks again for the code. I will give it a try in the morning and post my output.
 
Why not change the Perl to match the natural action of a form? If you don't want to do what's most logical, though, change the form method to post and that will prevent the data passed in the URL.

Lee
 
Trollacious,
good point. I have adjusted my perl script to take the natural action of the form. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top