PDA

View Full Version : Change Div on Refresh of page???



dhawal.mhatre
05-21-2009, 06:45 AM
Want to change the text in div on every refresh of the page. The text is not coming through database. The text is manually inserted.

I am new to java script and i am unable to do it. Kindly help me. It is required urgently. And i am working on PHP page.

Waiting for your replies....

Thanks in advance......:):):):):)

forum_amnesiac
05-21-2009, 06:58 AM
Is the text in the Div to be changed sequentially or randomly, ie you have text1, text2, text3, etc. If you have text1 currently displayed do you want text2 to be displayed on refresh or can it be either text2 or text3.

dhawal.mhatre
05-21-2009, 07:20 AM
any way will do.... sequentially or randomly

forum_amnesiac
05-21-2009, 07:25 AM
This link is discussing something similar, with an example script: http://www.dynamicdrive.com/forums/showthread.php?t=45102

Also thiis is referring to quotes there should be no unreasonable limit to the amount of text attached to each variable.

See if this points you in the right direction

dhawal.mhatre
05-21-2009, 07:32 AM
no friend...
its not working on random function...

i want it to change on refresh of page....

dhawal.mhatre
05-21-2009, 07:41 AM
i have JavaScript for refreshing images randomly.....


<head>

<style type="text/css">
div#container {
width:320px; margin-left:10px; margin-top:5px;}
img#random {
width:320px;
height:150px;
}
</style>
<script type="text/javascript">
//<![CDATA[

var images=new Array();
images[0]="images/1.jpg";
images[1]="images/2.jpg";
images[2]="images/3.jpg";
images[3]="images/4.jpg";
images[4]="images/5.jpg";
images[5]="images/6.jpg";

function randomImage() {
var i=Math.floor(Math.random()*images.length);
document.getElementById("customerreviews").src=images[i];
}
onload=randomImage;
//]]>
</script>

</head>

<body>
<div id="container"><img id="random" src="" alt=""/></div>
</body>

i try replacing images with text but its not working.....

forum_amnesiac
05-21-2009, 07:48 AM
Try using the function listed on the link for random quotes.

That should give different text on page refresh as well as when the page is opened if it is called inside your Div.

dhawal.mhatre
05-22-2009, 03:10 AM
i didn't understand you. Which function you are talking about.

please can you provide me with proper code:):):)

forum_amnesiac
05-22-2009, 06:59 AM
Here is a fairly simple script for displaying random text/quotes


function write_quote() {

var quotes = [
'no animals were harmed while making this page',
'made in ulm',
'this page was handmade',
'Get <a href="http://www.mozilla.org/products/firefox/">FireFox</a> :-)'
];

var r = Math.round(Math.random() * (quotes.length-1));

// write the quote
document.write(quotes[r]);

// or replace an HTML element:
// document.getElementById("quote").innerHTML = quotes[r];

}

Here is a link to another way of doing this using an external js file
http://wsabstract.com/script/script2/motivatequotes.shtml

dhawal.mhatre
05-23-2009, 02:47 AM
thanks a lot friend...
its done :):):):):)