Form builder generated HTML element id for Javascript

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Form builder generated HTML element id for Javascript

Karthi
Hi,

How to retrieve the dynamically generated HTML DOM id of a XForm control?
The form is generated using 'Orbeon Form Builder' and I would like to use this input ID from javascript that is included inside <xh:script> element from form builder source editor.

I tried below, but it seems that it works from the javascript that is included in the page where the Orbeon form is embedded?

var firstNameControl = ORBEON.jQuery('*[id $= "first-name-control"]')[0];
var firstName = ORBEON.xforms.Document.getValue(firstNameControl);

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Form builder generated HTML element id for Javascript

Alessandro  Vernet
Administrator
Hi Karthi,

I am not sure to understand what you mean by "it works from the javascript that is included in the page where the Orbeon form is embedded?". Whether you're embedding the form or not, it should work as long as you're not trying to run this from a different page (like a different iframe). Is calling this JavaScript causing you any trouble? Can you maybe tell us more what about your setup, the issue, and how we can reproduce it?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet
Reply | Threaded
Open this post in threaded view
|

Re: Form builder generated HTML element id for Javascript

Karthi
Hi Alex,

Below is the required feature,
Onclick of a radio button, open a 'java script' confirmation dialog.
Depending upon user action (ok or cancel) update an existing 'text output' control text.

In order to do this, if we have a feature to get the generated control's HTML ID, I can register 'onchange' event handler for radio button which will open up javascript confirm dialog and the sameway, I can update the 'text output' control's value when user responds the dialog with 'OK' response.

Please let me know if you need more details.

Thanks,

Reply | Threaded
Open this post in threaded view
|

Re: Form builder generated HTML element id for Javascript

Alessandro  Vernet
Administrator
Hi Karthi,

If you know the name given to the control in Form Builder, running the following will give you the id of the corresponding element in the DOM, here assuming you're looking for the id of a control named "first-name":

ORBEON.jQuery('*[id $= "first-name-control"]')[0].id

Note this doesn't return the HTML form element, but typically a container of that element. For an input field, you can get the actual HTML input field with:

ORBEON.jQuery('*[id $= "first-name-control"] input')[0]

Is this inline with what you were looking for?

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet