How can I get a variable label text?

gmorales
Kilo Expert

Hi everyone ,

I'm trying to get the Label text of a radio button and a check box once they are clicked, then after that they will be captured in a multi line text and etc..

I'm trying to use

g_form.getLabel('my_checkbox');

g_form.getLabel('my_radio_button');

But this doesn't seem to work, I'm trying to capture them when user is filling out a catalog item, the code just throw "false" as a value instead of the label text, has anyone know how to get the label text dynamically? I could do a conditional state which will put the value of the label to a variable but this will be hard coded and I'm not positive whit that idea.

4 REPLIES 4

Aditya Mallik
ServiceNow Employee
ServiceNow Employee

Hi,



Not sure in which release you are in. Did you try using



g_form.getLabelOf("my_checkbox")



using getLabelOf instead of getLabel should work.



Thanks.


Nana5
Mega Guru

Hi


  Please try with below line.in that u have to find out the id of the field.



var x = document.getElementById("ID of ur field").label;



Thanks


gmorales
Kilo Expert

Hi,


Thanks for your suggestions but none of them worked, I got a "null" response.


brian_degroot
ServiceNow Employee
ServiceNow Employee

Hello,



Try doing the following:



var labelElement = $('label.' + g_form.getControl(field).id);




Best regards,



Brian