how to call function by button click in same page??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mujaffar
Forum Newbie
Posts: 13
Joined: Tue Dec 22, 2009 11:16 pm

how to call function by button click in same page??

Post 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??
:roll:
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

Re: how to call function by button click in same page??

Post 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
mujaffar
Forum Newbie
Posts: 13
Joined: Tue Dec 22, 2009 11:16 pm

Re: how to call function by button click in same page??

Post by mujaffar »

hello thanks pauldr

please give me detailed example
can i use php code in that function?? :)
pauldr
Forum Newbie
Posts: 18
Joined: Fri Apr 10, 2009 6:40 am

Re: how to call function by button click in same page??

Post 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
Post Reply