Issue with document.getElementById in XPages

I have a Edit Box control with Name : “config_value”

I have a button control coded with the following client side java_script in it

var x=document.getElementById(‘#{java_script:getClientId(“config_value”)}’).value

alert (x);

This alerts what ever I put into the editbox control when I click the button.

But when I split up the same code in the following fashion it fails.

var test=‘“config_value”’;

var x=document.getElementById(‘#{java_script:getClientId(’+test+‘)}’).value

alert (x);

and the same gives me the following error message

The runtime has encountered an unexpected error.

500 Exception

Error while executing JavaScript action expression

Script interpreter error, line=1, col=1: Invalid component name

I have attempted eval() commands as well and it gives me the same error as well

It is mandatory that I should pass the id through a variable as mentioned in the second code fragment.

Please suggest me a work around for this issue

Thanks in Advance

(I have purposely used the word java_script for the sake of this post only.)

Subject: I thought #{id:} was for this?..

  • I can set a variable to that and it works:

var eltName:String=“#{id:someElement}”;

var domElt=document.getElementById(eltName);

  • Or am I missing something? Wouldn’t be the first time. (wry grin)

Hope this helps…

Subject: Re: I thought #{id:} was for this?..

Thanks for your reply,

Yes you are missing the point,

Your attempt say,

var eltName:String=“#{id:someElement}”;

var domElt=document.getElementById(eltName);

And my requirement is something like the following in your context,

var variable=“someElement”

var eltName:String=“#{id:”+variable+“}”;

var domElt=document.getElementById(eltName);

and this fails… hope I make more sense