Forum Moderators: coopster

Message Too Old, No Replies

PHP onclick change the include value

PHP onclick change the include value

         

fast4u

8:18 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Hello Everyone,

I have a quick question, should not be hard.

So Basically I am trying to figure out how can I create a link that will change the value of <>include<>.

I am trying to create alphabetized link directory, it just basically displays the whole alphabet on the page. Each letter on the page should be linked to a text file, that will have links with descriptions, now I came up with something like this below.

here is a little code


......
<td class="border" align="center"><a href="w.txt">W</a></td>
<td class="border" align="center"><a href="x.txt">X</a></td>
<td class="border" align="center"><a href="y.txt">Y</a></td>
<td class="border" align="center"><a href="z.txt">Z</a></td>
</tr>
</table>
<p align="center">
<?php include ("data.txt");?> //This is initial value.

And when I will click on "Z" (the link) on the page, I would like it to display the content of "z.txt" if it is possible?

I my explanations are now understandable please let me know.

Or maybe you can offer me another way.

Here are some images.

I hope to get the answer soon.

Thank you,

-Fast4u

[edited by: jatar_k at 8:21 pm (utc) on April 3, 2007]
[edit reason] no urls thanks [/edit]

jatar_k

8:22 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



trouble is that without sending info back to the server then php can't do anything as it is a server side technology

if you want to do this client side then you would need something like javascript/ajax

fast4u

8:25 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



jatar_k,

Thank you for responding so soon, apologize for posting images.

So basically there is no way to do that? Are you getting the idea of what I am trying to do?

jatar_k

8:29 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yep, I understand

if I wanted to do it with php I would change each txt file into a php file and then include my menus and whatever else I need

then have real links to those pages in my top menu

you could load them all and use layers/divs to switch them, not sure if that may be a lot of overhead for a single page though

fast4u

8:35 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



hmm,

so u are saying include all the pages at first?.......

jatar_k

8:45 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



possible, but it would really depend on how much data there is

I would definitely just go back and forth to the server on each click

fast4u

8:52 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



that is exactly what I want but, I don't want the page to reload, and you would probably say then use Iframes, but Iframes create scrollbars that I don't like. I want autofit!

eelixduppy

9:12 pm on Apr 3, 2007 (gmt 0)



You are going probably going to have to use javascript for this because you don't want the page to refresh. The way I see it, you have two options:

1) Load all of the content into a javascript array and each time a link is clicked, call a javascript function to print out the corresponding element in the array.

2) Use Ajax and get the content from other places on your server and print the data out according.

I'd say go with the first solution unless you have a lot of content that you want to display for each link. If that is the case, then you are probably better off going with the second.

Try to code this for yourself to see how far you can get. If you need further help, the folks over in the javascript forum will be happy to assist :)

Good luck!

capulet_x

11:48 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



I think you can turn off the scrolling in an iframe...

<IFRAME SRC="example.html" FRAMEBORDER="0" SCROLLING="no" WIDTH="1024" HEIGHT="768" TITLE="mydata_page">

Also I was wondering, does each page that is suppose to load have content on it that will change often? If no, if you are opposed to refreshing, you could simply use anchors to navigate around a page that contains all of your links.

<a name="label">Text to be displayed</a>

albeit not very elegant it is a simple solution...(of course you do get the scroll bar thing)

fast4u

7:52 pm on Apr 4, 2007 (gmt 0)

10+ Year Member



Okay i see what you are saying is there any way I can create a page with the whole content on the page, and then after that when someone clicks on the certain link it will just display the certain area of the page.

Anchor links are a good idea, but when you have only one line of text and the anchor link is on the last line of the page, then it does not really display the right data, it displays everything that fits in the certain window size!