I have a little more now. Here my advanced code.
The problem is, that it will loose the array whwnn i call muller
(new_item);
any solution here ?????
window.addEvent('domready', function() {
var path = 'http://api.kivaws.org/v1/';
var writehere = $('hierhin');
var rand = 0;
var arrayLaenge = 0;
var request = new Request.JSON({
url: path + 'lending_actions/recent.json',
onComplete: function(jsonObj) {
rand = $random(0, jsonObj.lending_actions.length-1);
arrayLaenge = jsonObj.lending_actions.length-1;
addText(jsonObj.lending_actions[rand]);
}
}).send();
var addText = function muller(item) {
var archiveHTML="<h3>Archive text von joe</h3>";
archiveHTML+="<div class=\"single\" id=\""+item.id+"\">";
archiveHTML+="<div class=\"post\"><div class=\"day\">"+item.date+"</
div>";
archiveHTML+="<div class=\"month\">"+item.loan.use+"</div>";
archiveHTML+="</div><h4>"+item.id+" <span class=\"author\"> by "+rand
+"</span></h4>";
archiveHTML+="<p>"+item.id+"</p></div>";
writehere.set('html', archiveHTML); //löscht vorhandenes und
trägt neues ein.
};
// Add Button to Change ArrayItem
$('more_changer').addEvent('click', function() {setStateForItem
(0);});
function setStateForItem(item)
{new_item = rand + 1;
if(new_item =(arrayLaenge+1)){new_item=0;};
alert(rand);
muller(new_item);
};
});
On 30 Okt., 12:44, hamburger <[email protected]> wrote:
> Hello, I have the following code witch works fine. But I'am a newbe
> and dont get what i want.
> I would like to display one line out of the jason request choosen
> randomly.
> After that i would like to have a button to scroll to the next line.
> Somebody can help??
>
> Thanx in advance.
>
> var path = 'http://api.kivaws.org/v1/';
> var writehere = $('hierhin');
>
> var request = new Request.JSON({
> url: path + 'lending_actions/recent.json',
> onComplete: function(jsonObj) {
> //var rand = $random(0,
> jsonObj.lending_actions.length-1);
> //addText(jsonObj.lending_actions[rand]);
> addText(jsonObj.lending_actions);
> }
> }).send();
>
> var addText = function(addArchiv) {
>
> zufall =$random(0,99);
> var name = new Element('h2', {'html': 'Hallo'});
>
> addArchiv.each(function(item, index) {
> //if(index==zufall)
> {
> var liste = new Element('ul', {'class': 'recentlist'}).inject
> (name);
> var el = new Element('li', {'html': 'index:'+index+' item:
> '+item.id+' <a href="'+item.date+'"
> class="loadMe">'+item.loan.use}).inject(liste);
> }
> });
>
> name.inject(writehere); // Einfügen bei id=hierhin
>
> };
>
>
>
> });- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -