bit of javascript help?
- Started
- Last post
- 7 Responses
- cramdesign
I need a bit of javascript that will choose from a list of divs and display one of those divs. I have no clue ... anyone willing to lend a hand or even a point in the right direction?
- acescence0
do you mean the user selects from a list and it shows that div? or it randomly displays one div on pageload?
- acescence0
do you mean the user selects from a list of divs and it displays that div?
- ayport0
prototype.js will get a div id by just using $('dividhere') http://www.prototypejs.org/
- d_rek0
Pretty sure you can do that with jquery:
http://docs.jquery.com/Ajax/load…
But be sure to get jquery first
- acescence0
well if that's all you're doing then a whole js lib is overkill, but if you've got lots of other js stuff to do it may be worth it. i can give you something more succinct if you could describe it more thoroughly.
- cramdesign0
Basically I want an array of info in an external file. I would like to use js to select one of these items and show it in a div in the footer. The javascript will choose from the array and randomly display one on pageload. Does that make more sense?
Thanks.
- cramdesign0
Got it. In hindsight, it was easy really. For the record:
var quotes = new Array;
quotes.push( "Text 1 here." );
quotes.push( "Text 2 here." );
quotes.push( "Text 3 here." );
function quote() {
var q = quotes[(Math.floor(Math.random() * quotes.length))]
document.write( q );
}Then call quote(); where I need it to be.