Page 1 of 1
Basic Function question
Posted: Fri Jan 24, 2003 11:14 pm
by smoky989
I feel dumb asking this but how do you call a function from a form button. Acrually the button doesn't have to be in a form but I want to call a functio onclick. I can't find it in the book I have. Any help? Thanks in advance
Posted: Sat Jan 25, 2003 12:36 am
by lazy_yogi
Put this into a file with .php extension and give it a go.
But this is executed server-side, I'm not sure if it can be executed in the clients browser like javasctipt is (I think javascript is executed client-side... not sure though .. only heard that).
Someone else might know
Hope it helps.
Code: Select all
<?
// The submit button is named 'send' below in
// the form and the form action calls the same
// script by using action=""
// So if the form was called by pressing the
// submit button, then it recalls this page and
// $send now exists (also $name holds what was
// put in the textfield called name blow in the form)
if ($send) { // if submit buttin in form below was
// pressed, then if($send) .. is called
printstuff($name); // call function here
}
else
{ // else print the form below
?>
<BR><BR><BR><FORM METHOD="POST" ACTION="">
<TABLE bgcolor = #f0f0f0 borderColor=gray cellPadding=3 border=2>
<TR><TD width = 80><CENTER>Username
<TD width = 120><CENTER><INPUT TYPE="text" NAME="name" size="15">
<TR><TD colspan=2><CENTER>
<INPUT TYPE ="submit" NAME="send" VALUE="SetCookie">
</TABLE>
</FORM>
<?
} // this closes the else statement
function printstuff($in) {
print "name is $in";
}
?>
Posted: Sat Jan 25, 2003 12:39 am
by volka
php runs serverside and has no connection to the "document" as soon as it is delivered to the client.
As long as actions stay clientside you have to use a clientside scripting language like javascript.
Posted: Sat Jan 25, 2003 7:44 am
by twigletmac