Thanks for the tip to avoid looping.
Everything works.
Josh
Joerg Heinicke wrote:
>
> On 07.10.2007 11:15 Uhr, [EMAIL PROTECTED] wrote:
>
>> I am uncertain about scope in JavaScript. I would never declare a
>> variable inside a block and expect the variable to be available
>> outside the block, but that rule is a LCD from using many programming
>> languages. If JS had an issue, this code should error about accessing
>> a missing property "nodeValue" from a null object.
>
> This is the actual reason. Even if it works at all (as you explain why
> it should not) the variable is declared only inside the loop and not
> available outside of it. Cocoon once had a feature to put non-declared
> variables into a global scope, but I thought this was somehow protected
> during method execution. Anyway, this means that you have a local
> variable inside the loop - and a different global one, conincidentally
> with the same name, which never gets set. But in that case you really
> should get an exception since you access the nodeValue property of null.
>
> The code has to change at least (besides possible DOM changes) to:
>
> var captchaUserEntries = root.getElementsByTagName("captcha");
>
> var captchaUserEntry;
> // get captcha node
> for (var i = 0; i < captchaUserEntries.getLength(); i++) {
> captchaUserEntry = captchaUserEntries.item(i);
> }
>
> // get required content
> var captchaUserContent = captchaUserEntry.nodeValue;
>
> Or to avoid the meaningless looping do:
>
> var captchaUserEntries = root.getElementsByTagName("captcha");
>
> var captchaUserEntry =
> captchaUserEntries.item(captchaUserEntries.getLength() - 1);
>
> // get required content
> var captchaUserContent = captchaUserEntry.nodeValue;
>
> (Both examples should have a check for the case there is no captcha
> element.)
>
> Hope this helps,
>
> Joerg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/How-to-get-same-function-as-java-loadDocument%28cocoon%3A-your.pipeline%29-in-javascript-flow--tf4581000.html#a13085776
Sent from the Cocoon - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]