[EMAIL PROTECTED] wrote:
> I found a workaround that someone else may find useful so I figured I'd
> share it. I wanted to load a dialog from a url
>
> Dialog.confirm( {url: "dialog_content.html", ...
>
> but set the initial value of an element in the fragment to that of an
> input already in the page once it's loaded.
>
> Inserting this:
>
> $('newElement').value = $F('oldInput');
>
> into the separate file (in script tags) fails because $('newElement')
> doesn't register until the window is created. However, this:
>
> setTimeout("$('newElement').value = $F('oldInput');", 0);
>
> works perfectly by waiting 0ms after the window div is added so that
> $('newElement') can be accessed normally. I'm curious if anyone knows a
> better way to do this short of making a separate ajax call and manually
> inserting the text into the responseText before creating the window.
Your code is not about an Ajax call. But if it were, you should consider
using the onSuccess callback from Prototype.
Using setTimeout is usually a bad idea, because if content or elements
are deferred (i.e., not directly created while the script runs
sequentially), you will have a problem once it takes more than one clock
cycle to create 'newElement'. Instead, write a method that tests each
100 ms or so for the newElement to appear and call you your function
(setting content in the newElement) once the newElement does get
available. You may want to add a timeout, something like: if tried for
10x, something may have gone wrong, so stop testing for that element:
// todo: add some pre-/-post condition checks
function executeWhenExists(elem, callback) {
if($(elem))
callback();
else
setTimeout(function(){executeWhenExists(elem, callback)}, 100);
}
Cheers,
-- Abel Braaksma
_______________________________________________
Javawin mailing list
[email protected]
http://mail.xilinus.com/mailman/listinfo/javawin_xilinus.com