Onclick = jump to another part of php script

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
kcp88
Forum Newbie
Posts: 8
Joined: Mon Aug 22, 2011 11:51 pm

Onclick = jump to another part of php script

Post by kcp88 »

Can anyone help me ? My PHP version is 5.2.17 .

Let's say I got a php script called abc.php . And then I after I load the page , I echo something like below :

Code: Select all

<td colspan="21" align="center"><a href="#" onclick= ??? >Click Here</a></td>
For the above click here , I need it to execute the page again , but it shall start from another part , not the beginning of the php script . What can I do on the onclick ?

Any idea how to do it ?
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Onclick = jump to another part of php script

Post by manohoo »

Code: Select all


... onclick='window.location.href=abc.php?click=1'.... 

// abc.php could have this structure:

if (!isset($_GET['click']) {
   // BLOCK1 code
} else {
   // BLOCK2 code
}
kcp88
Forum Newbie
Posts: 8
Joined: Mon Aug 22, 2011 11:51 pm

Re: Onclick = jump to another part of php script

Post by kcp88 »

Hi, Thanks for reply . But seems like it is not working , after i click , it changes to abc.php# , but not abc.php?click=1 . If i use

Code: Select all

<a href="abc.php?click=1">click here </a>
,

then the data in the page will loss ....
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: Onclick = jump to another part of php script

Post by twinedev »

The reason you gent to abc.php# is because that is the link you clicked on. You would need to add ;return false; to the end of the example given by manohoo. However even then it will be taking you to a new location as in the last example you gave.

You either need to have it do an ajax call back to the script and then process the results, or find a way to include ALL your data into the link.

-Greg
kcp88
Forum Newbie
Posts: 8
Joined: Mon Aug 22, 2011 11:51 pm

Re: Onclick = jump to another part of php script

Post by kcp88 »

Thanks for reply . I'll have a try first before I ask again , haha I am new to PHP.
kcp88
Forum Newbie
Posts: 8
Joined: Mon Aug 22, 2011 11:51 pm

Re: Onclick = jump to another part of php script

Post by kcp88 »

But how to use ajax call only certain part of the php script ? Can guide me ?
Thanks first !
Post Reply