Page 1 of 1
how to call function by button click in same page??
Posted: Wed Dec 30, 2009 1:09 am
by mujaffar
hello friends
how to call function by button click in same page??
i know the submit button and form action method
but this is done only to redirect for that page only
i want to call different function for different buttons respectively
can i use jscript to it ?? how can i do it??

Re: how to call function by button click in same page??
Posted: Wed Dec 30, 2009 2:45 am
by pauldr
Instead of using buttons, if I need to call a function I use an html anchor tag.
Example:
<a>href="javascript:document.forms['form_name'].action = '/path/to/function/function-name; document.forms['form_name'].submit();">Function Name</a>
Paul
Re: how to call function by button click in same page??
Posted: Thu Dec 31, 2009 12:51 am
by mujaffar
hello thanks pauldr
please give me detailed example
can i use php code in that function??

Re: how to call function by button click in same page??
Posted: Thu Dec 31, 2009 3:13 am
by pauldr
Yes, you can use php inside the anchor tag. For instance, on one of my sites I have the following code:
<a href="javascript:document.forms['site_form'].action = '/inventory/add-item?id=<?=$item['id']?>'; document.forms['site_form'].submit();">Submit</a>
add-item is the name of the function and I'm passing an integer to the function. I have the integer inside php tags.
Paul