View Full Version : Possible to load new text on same page?
petternitter
04-06-2008, 09:14 AM
Hello,
I'm wondering if it is poissble to load new text on the same page when you click a navigation button? E.g. if you create index.htm and you have a navigation with 5 buttoms and introduction text. When clicking one of the nav buttons you are not redirected away from the page to e.g. music.htm, only the introduction text changes, but the page is still index.htm.
Is this even possible or?
Majoracle
04-06-2008, 10:23 AM
You can do this with some simple CSS and JavaScript. Make sure the IDs match where I colored them in blue.
JavaScript:
<script type="text/javascript">
function showDescription(id)
{
var el = document.getElementById(id);
if (el.style.display == 'none')
el.style.display = 'block';
else if (el.style.display == 'block')
el.style.display = 'none';
}
</script>
Image Link:
<a href="javascript:showDescription('music');"><img src="musicbutton.gif" alt="" /></a>
Description Block:
<div id="music" style="display:none">
...your description here...
</div>
Clicking the button once will show the description, clicking it again will hide it.
petternitter
04-06-2008, 11:56 PM
Never used javascript, but I will give it a wirl.
However, I'm also thinking of using this for MySpace in the future and since they do not allow javascript, is there any way to do this with just CSS and HTML?
Thanks for the post.
Majoracle
04-07-2008, 01:19 AM
No, there's no way to do it without JavaScript. Sorry.
Accomplishing this would be beyond what you're allowed to do on MySpace.
_Aerospace_Eng_
04-07-2008, 01:23 AM
You could do it in flash maybe but updating things would be a pain.
DonSailieri
04-07-2008, 04:00 AM
I recently asked myself the same question - and came up with a php solution!
This is realtively easy to code and you can make it up yourself if your into the language a bit (that's how I did it).
My goal was the same as yours: to display different content on the same index.php when clicking a link. The solution is that, instead of making the links redirect to another file, make them assign a value to a variable!
this would for example look like this:
<a href="?content=music">Music</a>
that doesn't redirect you to another page but just assigns the value "music" to the variable "content" (you can name them in whatever way you want of course). It adds an appendix to the url, so it would go from
http://yourdomain.com/index.php
to
http://yourdomain.com/index.php?content=music
So you're still on the same page/file. All that the new url says is
"Youre on the index.php AND the variable content equals music!"
But how does this help with displaying differing content? Well to make it work, your index.php will need to work with a simple if statement and php includes. Your index.php (yes, it's gotta be .php - but don't worry it won't make much of a difference ;)) will look like this:
[...]
<body>
<a href="?content=home">Home</a>
<a href="?content=music">Music</a>
<?php
$content= $_GET[content];
if ($content== "home") {
include ('home.php');
}
elseif ($content== "music") {
include ('music.php');
}
elseif ($content== "") {
inlude ('home.php');
}
?>
</body>
I'll just assume here that you've never worked with php before and so I'll explain that code snippet line by line.
First you got your navigation, assigning values to variables, after that, the php code follows. First of all the code needs to know what to do with the variable 'content'.
$content= $_GET['content'];
just means that the variable content's got the value we assigned to the variable 'content' up in the hrefs.
Now, the if statement kicks in. I'll just translate what it does:
If the variable 'content' has the value 'home', the content of home.php will be displayed here (in this case you have to save the actual content of your home to a separate file called home.php)
Else, If the variable 'content' hast the value 'music', the content of music.php will be displayed here (again, the content of your music page has to be stored in a file called music.php)
And finally, if the variable 'content' has NO VALUE (and it doesn't have one when you first come onto the site since you haven't clicked on any links yet and assigned a value) the contents of home.php will be displayed here. This just ensures that you'll see the content of 'Home' when you first visit the site.
And that's it already! You can see this technique in action here:
http://saugi.pointclark.net/newHaase
I hope I got this across quite good - please excuse if I overexplained everything =)
Anymore questions more than welcome!
Don
_Aerospace_Eng_
04-07-2008, 04:19 AM
That would work in a normal web environment however they may want to use this on MySpace and we all know that myspace isn't a normal web environment.
petternitter
04-07-2008, 07:34 AM
Using flash sounds like a solution for MySpace, but I'm not very savvy at flash and yes, it would be a buttock to update.
Thanks for the help tho. Will try and use the javascript for the website.:thumbsup:
DonSailieri
04-07-2008, 08:38 PM
Uh, i hastly overread the myspace part... anyway, feel free to use my solution if you fell like it =)
Don
ClaudiuCC
08-18-2008, 12:15 AM
I recently asked myself the same question - and came up with a php solution!
This is realtively easy to code and you can make it up yourself if your into the language a bit (that's how I did it).
...
Anymore questions more than welcome!
Don
I like this thing and I would like some instructions please.
I don't understand how to place the content for this.
Can you make a 3 page sample and mail me or attach a rar/zip file here?
The pages can have some dummy text to fill a row for content.
Please make it with header, center content, footer.
I'm asking this because my level of php is 0. I can only read things written in php.
Thank You
Regards
ch4sethe5un
08-19-2008, 02:17 AM
i am no expert, but can't you use this tutorial and apply it to the whole page content and navigation?
http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/
Non-autoplaying of course...
He applied this to his sidebar, on the right, labeled with script style/featured articles/popular articles.
:D
rhinodog8
08-19-2008, 02:24 AM
You can insert the text in an iframe
<iframe scr="oldtext.html" name="frame"></iframe>
link code:
<a href="newtext.html" target="frame">nav bar code</a>
oldtext.html=a simple path to a html page with the old text before changing
newtext.html=a simple path to a html page with the new text
----------------
pretty sure this allow on Myspace BTW.
rhinodog8
08-19-2008, 02:27 AM
No, there's no way to do it without JavaScript. Sorry.
False.
ClaudiuCC
08-19-2008, 11:49 AM
i am no expert, but can't you use this tutorial and apply it to the whole page content and navigation?
http://css-tricks.com/creating-a-slick-auto-playing-featured-content-slider/
that's why your question is stupid ...
ch4sethe5un
08-19-2008, 04:13 PM
that's why your question is stupid ...
not being an expert = stupid ???
ClaudiuCC
08-19-2008, 04:30 PM
read again ... 'stupid question' is mentioned ..
rmedek
08-19-2008, 07:47 PM
ClaudiuCC, take a moment to read the Rules before posting another message. Insulting members or just plain being rude is not tolerated.
ClaudiuCC
08-19-2008, 07:51 PM
okok.. .. anyway ...
anyone can help me with my question? I'm willing to give $7 to whom can make me what I asked for.
ClaudiuCC
08-22-2008, 06:27 AM
I recently asked myself the same question - and came up with a php solution!
...
I hope I got this across quite good - please excuse if I overexplained everything =)
Anymore questions more than welcome!
Don
your code is missing something.
check here (http://claudiudesign.org/temp/dinamic/home.php) to see error on it
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.