Click to See Complete Forum and Search --> : Calling function using button....


daimous
12-27-2004, 10:48 AM
Can anyone help me pls....how can i call a function with PHP script on it by using button and can anyone give me pls. a link for toturial to solve this problem? tnx! in advance...

cyber1
12-27-2004, 12:27 PM
It is no different than calling an HTML file.
Use the onClick handler.

Now if you want data from the form/page thats a bit more complicated.

Could you post a few more details as to what you are trying to do.
Code you have so far.

-Bill

daimous
12-27-2004, 12:35 PM
<?
function msg(){
print "PHP Script....";
}
print "<button onclick=....."; //what now?
?>
how can i call the msg function using a button or
i want a button that will call the msg function when clicked.
tnx! in advance...

baseiber
12-27-2004, 12:47 PM
I suggest you click here (http://www.google.com) and do a search for html calls javascript and something like call php functions.

Try doing a little research. You'll learn better that way.

cyber1
12-27-2004, 01:08 PM
The following example shows a way of doing what you ask for although there are easier ways I'm sure but this is 'one way'

There are certainly easier ways to redirect to a different url but that is not the point of this example.

-Bill

This goes into you HTML file
<html>
<head>
<title>Untitled Test</title>
<script language="JavaScript">
<!--
function loadSponsorUrl(form){
var_sponsors_url = (form.var_sponsors_tokens.options[form.var_sponsors_tokens.selectedIndex].value)
var newWindow = window.open("","datafiles","location=yes,status=yes,menubar=yes,toolbar=yes,scrollbars=yes,resizable=yes,left=250,width=950,top= 20,height=900")
newWindow.location ='http://fullurlto/test.php?var_sponsors_url='+var_sponsors_url+'';
}

// -->
</SCRIPT>
</head>
<body>
<form method="get">
<input type="button" value="Show Site" onClick="loadSponsorUrl(this.form)"> &nbsp;&nbsp;&nbsp;
<select name="var_sponsors_tokens" size="1">
<option value="google">Google
<option value="yahoo">Yahoo
</select>
</form>
</body>
</html>





Then create a file called test.php

<?php
parse_str($_SERVER['QUERY_STRING'],$vars);
$var_sponsors_url =$vars['var_sponsors_url'];
$url = "http://www.$var_sponsors_url.com";
header("Location: $url");
?>