How to access propperties of g_form elements listed as an array

carlos_salgar
Kilo Explorer

Hi,

I am creating a list with all the elements of a g_form with elements method (i need the list to iterate through all the elements of the g_form)

However, when I try to get the value of every element, (for example g_form.elements[2])   I always get 'undefined'.

I am having issues in general to acces any attribute/properties of these elements.   I need to verify if the element is hidden as well

How can I get all the attributes an methods of the elements?

function onSubmit() {

     

alert(g_form.elements[2].isSectionVisible()); //does not work

alert(g_form.elements[2].value); // doesnot work

alert(g_form.elements[2].getValue()); // doesnot work

}

Thanks

16 REPLIES 16

gauravchoudhury
Tera Guru

Hi Carlos,



Please refer to this link for your reference.


Shahed Shah1
Tera Guru

The format of getting a value of a field is g_form.getValue(). So you would need to call it differently. So:


g_form.getValue(g_form.element[index].getID())



Here's an example of iterating through the elements array and getting the values:


g_form.elements.forEach(function(element) {


      console.log(element.fieldName, "=", g_form.getValue(element.getID()));


});



Hope this helps



EDIT: Updating script for slightly cleaner output.


Hi Shahid,



Thanks for your help.



It seems to be better now, however, for some reason, the getValue method is returining empty strings for all fields even when the fields have some content on it (i am testing it with some text boxes which I add content before applying the script).   I am applying the script in the "onSubmit" event.   See script below:



find_real_file.png


Hi Carlos,



I have tried below code onLoad client script and it works for me, please make sure you use getDisplayValue for reference field.



function onLoad() {


var fieldslist = '';


var count = 0 ;


for(var i =0; i<=6; i++)


{


if(count > 0)


fieldslist = fieldslist +","+ g_form.getValue(g_form.elements[i].getID());


if(count == 0){


fieldslist = g_form.getValue(g_form.elements[i].getID());


count += 1 ;


}


}


alert("Field list of the incident table is : " +fieldslist );


}