By wickus on
I have the following simple example:
<script>
var titel = new Array(1,2);
for(var i=0; i< titel.length; i++){
alert(titel[i]);
window.setTimeout("document.getElementById('main').innerHTML = titel[i]",2000);
}
</script>
The id main is in the body tag.
Question: Why will the title[i] be shown in the alert, but not in the setTimeout? I get a undefined in the body Tag
Thanks in advance
Comments
just guessing, but try this
- Robert Douglass
-----
My Drupal book: Building Online Communities with Drupal, phpBB and WordPress
i
After the 2 seconds is up, i will be 2... and both timeouts will do the same thing. Just guessing
Scope
Your 'titel' variable is probably not in scope when the timeout fires. Use a closure instead:
--
If you have a problem, please search before posting a question.
I assume the whole thing is
I assume the whole thing is still within a for loop? At least I tried it with this and it still showed up the last piece of content in the array.
I try to refresh only the div main in my drupal page. I found the ajax.updater in prototype but it seems to refresh full nodes or pages into the given part. So it looks bad when the full node with the surrounding blocks will be reloaded in the div main .
I try to set up a database where folks can put in the node id and a time to refresh, with this node id they get the title and body from the node_revisions table which shall be refreshed in this given time in the div "main" part of the drupal page. Maybe somebody has a solution for this?
Thanks
Wickus
---
Join the virtual march to stop global warming.
http://www.stopglobalwarming.org/marchers/?142067
Rough but functional...
Try this. Put this code in your <head>:
Call the function advance() when the page loads. This script starts changing the value of
mainright away, instead of waiting two seconds. This would be easy to change with another setTimeout().wow groovy, that could
wow groovy, that could probably help me. thanx a lot
---
Join the virtual march to stop global warming.
http://www.stopglobalwarming.org/marchers/?142067
why is the german Ü = ü
why is the german Ü = ü when first urlencode it and then try to decode it again? seems to be pretty weird to me?
Had the problem with the php db data I passed to js, so I rawurlencode it before and then in the innerHTML I unescape the stuff again and it came out like this. Tried to replace it with the js replace function but no change.
---
Join the virtual march to stop global warming.
http://www.stopglobalwarming.org/marchers/?142067
Don't know, but...
I know barely anything about encoding/character escaping, but since no one else seems to be writing back I thought I'd post. Would it make any difference if you used base64 (base64_encode()) or uuencode (convert_uuencode(), PHP 5 only) encoding instead of URL encoding? There are many Javascript base64 decoder scripts available. I'm guessing the problem is that you're using a Unicode character which is not being handled properly by the encoder/decoder you're using.
Ajax Refresh of <div class='main'>
due to pears447 help with his advance function I finally got it done, sorry it took so long to post the stuff here:
unfortunately I can't upload the files here so I try to include the code:
You need to create a table, in my case I called it autorefresh,
Watch out if you have a table called like this, it will be dropped due to the first line.
The following code is the file autorefresh.php which will gather the data from the node_revisions table. This file will be called by the sndReq() Function from the ajax js functions file I called it mwajax.js (the utf8_encode will be needed when you have german or whatever specialchars in your language):
In the first line of the page.tpl.php I put the following code: (I think I put it in there because it was corresponding with some JS code you will see later in the head of the page.tpl.php
In the HEAD section I added first my ajax js functions file
The content of this file (mwajax.js) is :
Beside this I added the following code in the HEAD
I hope you can find some use in it, sorry its my first time to post some code. I tried of course the ajax.refresh from the prototype.js but in there it seems that it refreshes the whole node, which is not so nice especially when you load the whole node again in the div main (the blocks appear double then on the left and right. And why loading the whole node with the blocks when you can only load the main part. The only problem I have is that the refreshed pages are not editable when you logged in. You need to look them up through the admin menu. Maybe somebody gets a solution for this.
Greetings and thanks for you patience.
---
Join the virtual march to stop global warming.
http://www.stopglobalwarming.org/marchers/?142067