...

View Full Version : Quote Rotation Without Page Reload.



CBaZ
06-18-2008, 05:25 PM
I just have a question how to use ajax or any javascript with this. I have quotes rotating at page reload but am wondering how to have them change withour reloading.

<code>
<?php

$quoteFile = file("quotes.txt");
shuffle($quoteFile);

echo "$quoteFile[0]<br />\n";

?>
</code>

rnd me
06-18-2008, 05:51 PM
<script>
//support code
function IO(U, V) {
//LA MOD String Version. A tiny ajax library. ny DanDavis
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
X.open(V ? 'PUT' : 'GET', U, !1);
X.setRequestHeader('Content-Type', 'text/html')
X.send(V ? V : '');
return X.responseText;}

function Rnd(w) {return parsetInt(Math.random() * (w + 1));}
Array.prototype.random = function () {return this[Rnd(this.length - 1)];}



//now custom code

var allQuoes = IO("quotes.txt").split(/\r?\n/g);
document.getElementsByTagName("code")[0].innerHTML = allQuotes.random();
</script>

CBaZ
06-18-2008, 07:06 PM
I get an error on this line.

document.getElementsByTagName("code")[0].innerHTML = allQuotes.random();

it says its null or not an object ?

rnd me
06-19-2008, 03:38 AM
i assumed from the code you posted that you were using a <code> tag to display the quote.

if you dont, put some tag in your document where you want the quotes to land, and give it an id attrib; for instance:

<div id="output">Loading Quote...</div>


then replace the bad line in my first post with :


document.getElementById("output").innerHTML = allQuotes.random();

Dondon
06-19-2008, 05:21 AM
Uh, like this (http://dynamicdrive.com/dynamicindex2/generaltick.htm)?

CBaZ
06-19-2008, 06:46 AM
ok I have it like this and now my error is expecting an object.

<script>
//support code
function IO(U, V) {
//LA MOD String Version. A tiny ajax library. ny DanDavis
var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
X.open(V ? 'PUT' : 'GET', U, !1);
X.setRequestHeader('Content-Type', 'text/html')
X.send(V ? V : '');
return X.responseText;}

function Rnd(w) {return parsetInt(Math.random() * (w + 1));}
Array.prototype.random = function () {return this[Rnd(this.length - 1)];}



//now custom code

var allQuotes = IO("quotes.txt").split(/\r?\n/g);
document.getElementsByTagName("output").innerHTML = allQuotes.random();
</script>
<div id="output"><?php

$quoteFile = file("quotes.txt");
shuffle($quoteFile);

echo "$quoteFile[0]<br />\n";

?>
</div>

rnd me
06-19-2008, 07:51 AM
document.getElementById("output").innerHTML = allQuotes.random();

CBaZ
06-19-2008, 10:27 AM
document.getElementById("output").innerHTML = allQuotes.random();

is null or not an object error :(

CBaZ
06-19-2008, 09:58 PM
it might be due to me using the same

getElementById

in another script which is my banner rotation sript that is probably what's throwing it off is there anyway I can have both run at the same time?

rnd me
06-19-2008, 10:08 PM
hmm no ideas. yes, you can run several scripts at once.

repost the whole page as you have it now and i can take a look at it...

CBaZ
06-19-2008, 11:09 PM
I of course have banner ads filled in on my own site just for this post I have stripped them to display my code :) hopefully this helps shed light on the issue at hand. thanks.
this is the right margin of the site. the other functions which are called up o in the rest of the site are functioning properly.

<script type="text/javascript">

adds=[ // url,alt,image

["url","alt","image"],

["url","alt","image"],


["url","alt","image"]

]

count=0
count = Math.floor(Math.random()*adds.length);
onload=function test(){
MaloriaN.start();
test2();

oLink=document.getElementById("mylink")
oImg=document.getElementById("myimg")



oLink.href=adds[count][0]
oImg.alt=adds[count][1]
oImg.src=adds[count][2]

count++
if(count==adds.length){
count=0
}

setTimeout("test()",48000)
}


</script>
<a id="mylink" href="#null" target="_blank"><img id="myimg" src="" alt="" style="width:125px;height:125px" border="0"><div id="mytxt"></div></a>

<b><font size="2" color="darkblue"><tr><td colspan=2 align=center><hr color="#F6EED0" noshade SIZE="3" width="130"><strong><b><font size="3" color="#F6EED0"><center><img src="main/feedback.gif" width="100" height="15" border="0"></center></font></b></strong><b><font size="2" color="darkblue"><hr color="#F6EED0" noshade SIZE="3" width="130">
<i>
<?php

$quoteFile = file("quotes.txt");
shuffle($quoteFile);

echo "$quoteFile[0]<br />\n";

?>
</i><br><a href=quote_add.php onClick="NewWindow(this.href,'client_add','450','480','no');return false" onMouseOver="window.status='Leave your Feedback'; return true" onMouseOut="window.status=''; return true" target=_blank><font size=2 color="navy">- Send Us Feedback -</font></a><br>
<FORM enctype="text/plain" onSubmit="return sendMail()" METHOD="POST" ACTION="mailto:webmaster@webmaster.com?subject=Feedback">
<TABLE WIDTH="50&#37;" BORDER="0" CELLSPACING="0"
CELLPADDING="0" ALIGN="CENTER">
<div align="center"><br>
<script language="javascript">
// Author: Eric King Url: http://redrival.com/eak/index.shtml
// This script is free to use as long as this info is left in
// Courtesy of SimplytheBest.net (http://simplythebest.net/info/dhtml_scripts.html)
var win = null;
function NewWindow(mypage,myname,w,h,scroll){
LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
settings =
'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable= no'
win = window.open(mypage,myname,settings)
}
</script><br>

CBaZ
06-22-2008, 03:17 AM
any ideas as to why the feedback still gives me errors with the current coding



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum