Page 1 of 1

Onclick = jump to another part of php script

Posted: Mon Sep 05, 2011 12:01 am
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 ?

Re: Onclick = jump to another part of php script

Posted: Mon Sep 05, 2011 1:06 am
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
}

Re: Onclick = jump to another part of php script

Posted: Mon Sep 05, 2011 2:20 am
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 ....

Re: Onclick = jump to another part of php script

Posted: Mon Sep 05, 2011 4:02 am
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

Re: Onclick = jump to another part of php script

Posted: Mon Sep 05, 2011 4:17 am
by kcp88
Thanks for reply . I'll have a try first before I ask again , haha I am new to PHP.

Re: Onclick = jump to another part of php script

Posted: Mon Sep 05, 2011 5:07 am
by kcp88
But how to use ajax call only certain part of the php script ? Can guide me ?
Thanks first !