Basic Function question
Moderator: General Moderators
Basic Function question
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
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.
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";
}
?>
Last edited by lazy_yogi on Sat Jan 25, 2003 12:40 am, edited 1 time in total.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK