Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 06-06-2006, 11:51 AM DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Hi,

Is there anyone who can write a simple code for refreshing the contents of only one DIV container on one page? What I need is when someone clicks on "more..." link, only the content of that particular container will change. The rest of the page will stay the same.
frofi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-06-2006, 12:24 PM Re: DIV content refresh
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Code:
<script type="text/javascript">
<!--
function replaceContent() {
 
     document.getElementById("your_div").innerHTML = "Some new content."
 
}
-->
</script>
...
<a href="#" onclick="replaceContent()">more...</a>
That's it in its simplest form. Modify accordingly.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-06-2006, 12:44 PM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Thanks, ADAM. I'll try it out tonight.
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 10:41 PM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
The code works fine but it does the job only once. I don't know how to re-use it. The content is too large for only one reload. I'll try and investigate AJAX code. What I need is a code that can read for example .txt files or any other type which could contain the text I need to reload. I would split the content into a few of those. I don't know if that is possible or not, though.
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 11:00 PM Re: DIV content refresh
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Code:
<script type="text/javascript">
<!--
function replaceContent(show) {
 
     var display = new Array();
     display[1] = "Some new content.";
     display[2] = "Some other content.";
     display[3] = "Some more content.";
     
     document.getElementById("your_div").innerHTML = display[show];
 
}
-->
</script>
...
<a href="#" onclick="replaceContent(1)">more1...</a>
<a href="#" onclick="replaceContent(2)">more2...</a>
<a href="#" onclick="replaceContent(3)">more3...</a>
<div id="your_div"></div>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-06-2006, 11:18 PM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Thank you!
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-07-2006, 12:02 AM Re: DIV content refresh
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
FYI, frofi: my post was not meant to be the be-all and end-all answer to your problem, but to give you an idea of how the content is replaced. Sometimes it's good to play with code, deconstruct it, see what it does, and then you can manipulate it for your own evil purposes.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-07-2006, 08:28 AM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Quote:
Originally Posted by ADAM Web Design
FYI, frofi: my post was not meant to be the be-all and end-all answer to your problem, but to give you an idea of how the content is replaced. Sometimes it's good to play with code, deconstruct it, see what it does, and then you can manipulate it for your own evil purposes.
I uderstand that. But I know nothing about Java. I've managed to play and adjust code for displaying time and date but this time there was no way for my logic to come up with (show) or display[1], [2]....
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-07-2006, 06:03 PM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Everything is working fine except for text decorations (like bold or color). The java code doesn't seem to accept HTML within the replaced text which, of course, disturbs the page design. Is there a way around it? Please, have a look at www.frofi.co.uk/new/index.htm
I need the code for the window on the left. When you click on "more..." it displays the rest of the article. Then another one must start... Blue line, bold title and then text.


__________________________________________________ ______________________________________
Are you ignoring me? We'll see if you still be ignoring me after I've taken action against your family and friends.

Last edited by frofi; 06-07-2006 at 10:32 PM..
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-08-2006, 02:44 PM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
Now here is what I meant! It took me about 24 hours to find the code. I still can't make more than one reload, but at least it accepts HTML. If anyone knows how to make it work over and over again in the same DIV container, please let me know.
Code:
<script language="javascript">
function loadurl(dest) { 
try {
xmlhttp = window.XMLHttpRequest?new XMLHttpRequest():
new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { /* do nothing */ }

xmlhttp.onreadystatechange = triggered;
xmlhttp.open("GET", dest);
xmlhttp.send(null);

}
function triggered() {
if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
document.getElementById("yourDiv").innerHTML = xmlhttp.responseText;}
}
</script>

<div id="your div" onclick="loadurl('/yourFolder/yourFile.txt')">Initial content</div>
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)

Last edited by frofi; 06-08-2006 at 02:50 PM..
frofi is offline
Reply With Quote
View Public Profile
 
Old 06-14-2006, 11:55 PM Re: DIV content refresh
Ultra Talker

Posts: 256
Location: Auckland, New Zealand
Trades: 0
Hey frofi,

The code you posted I fully understand is what has been coined the term AJAX, To do what you want is not easy and could take you a while to actually understand how it all works.

To simply outline what happens:

When a request from your page asks for content from somewhere else (another page, output from a script, etc).

You remain on your page, till the content has been fully loaded and sent back to you, from there you take that content and you manipulate it into your site.

That manipulation into your site will appear instantly as if new content has been added, refreshed, etc (well it should do but in some circumstances caching problems get in the way).

I know this sounds like what you want, but the code above you provided does not handle the caching problems that you face with IE, I guess just changing this line to:

HTML Code:
xmlhttp.open('GET', dest + encodeURIComponent('?time=' + new Date().getTime()));
May or may not work, but you do need to append a randomly generated string on the end of the URL so IE thinks it's a new page request otherwise it will continue to use it's own cache.

Cheers,

MC
__________________
#------------------------------signature---------------------------------------------------------------------------------#
Quote:
I am well recognised for what I don't do than what I do. Chores are just one of those things.
mastercomputers is offline
Reply With Quote
View Public Profile Visit mastercomputers's homepage!
 
Old 06-15-2006, 12:50 PM Re: DIV content refresh
frofi's Avatar
Extreme Talker

Posts: 236
Location: London
Trades: 0
I understand how it works and that's why I know it needs some special code. I also understand what your solution brings. The problem is, it will load the same .txt file over and over again with every click. What I want it to do is to load a different .txt file (a specified one or in some logical order) with every click, so that the continuity of text doesn't break.
__________________
THE FORCE is with me at last! All I need now is some TALKUPATION ;)
frofi is offline
Reply With Quote
View Public Profile
 
Old 08-10-2006, 10:19 PM Re: DIV content refresh
Junior Talker

Posts: 1
Trades: 0
Quote:
Originally Posted by mastercomputers View Post
Hey frofi,

The code you posted I fully understand is what has been coined the term AJAX, To do what you want is not easy and could take you a while to actually understand how it all works.

To simply outline what happens:

When a request from your page asks for content from somewhere else (another page, output from a script, etc).

You remain on your page, till the content has been fully loaded and sent back to you, from there you take that content and you manipulate it into your site.

That manipulation into your site will appear instantly as if new content has been added, refreshed, etc (well it should do but in some circumstances caching problems get in the way).

I know this sounds like what you want, but the code above you provided does not handle the caching problems that you face with IE, I guess just changing this line to:

HTML Code:
xmlhttp.open('GET', dest + encodeURIComponent('?time=' + new Date().getTime()));
May or may not work, but you do need to append a randomly generated string on the end of the URL so IE thinks it's a new page request otherwise it will continue to use it's own cache.

Cheers,

MC
Interesting note. I'm wondering if there is a way to make the div refresh instead of firing onclick?
kpirnie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to DIV content refresh
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.62643 seconds with 12 queries