document.getElementById : how to set value when there is no ID?

andy_dufresne
Tera Expert

I need to set some values from the console in this process I have used something similar on the same form and works great:

document.getElementById("s2id_sp_formfield_subcategory").value = "Car Hire";

The above was a text field.

I have a reference variable and I want to add value similar to above.  The problem is I cannot find the 'ID'.  What options do I have to populate in that text box from console as above?

 

find_real_file.png

17 REPLIES 17

andy_dufresne
Tera Expert

This article says I can use angular.element(myDomElement).scope();

 

Here is what I have, what could be myDomElement here?  I tried few options it appears I'm going in circles 🙂

 

-------------------------------

<div class="reference">
    <div class="select2-container select2-reference select2-allowclear ng-isolate-scope ng-form-element" id="s2id_sp_formfield_subcategory" style="min-width: 150px; opacity: 1; width: 100%;">
        <a href="javascript:void(0)" class="select2-choice form-control" tabindex="-1" aria-hidden="true">
            <span class="select2-chosen" id="select2-chosen-1">
                <span class="sr-only">Lookup using list</span>
            </span>
            <abbr class="select2-search-choice-close"></abbr>
            <span class="select2-arrow" aria-hidden="true">
                <b></b>
            </span>
        </a>
        <input class="select2-focusser select2-offscreen" type="text" role="combobox" aria-label="To get started-type a word related to your question and select the most relevant option from the list" aria-required="true" aria-expanded="false">
        </div>
        <input type="text" name="subcategory" ng-disabled="snDisabled" style="min-width: 150px; opacity: 1;" aria-hidden="true" field="field" sn-select-width="100%" ref-table="formModel.table" ref-id="formModel.sys_id" glide-form="getGlideForm()" sn-options="{placeholder: field.placeholder}" record-values="getEncodedRecordValues()" sn-disabled="field.isReadonly()" label-id="sp_reference_element_sr_subcategory" class="ng-isolate-scope select2-offscreen" role="textbox" tabindex="-1" title="To get started-type a word related to your question and select the most relevant option from the list">
        </div>

-------------------------------

 

Here is all the combinations I tried:  

So either I get 'undefined' error or I get something like this:

VM512:1 Uncaught ReferenceError: reference is not defined
at <anonymous>:1:17

 

angular.element(reference).scope();
angular.element(select2-container select2-reference select2-allowclear ng-isolate-scope ng-form-element).scope();
angular.element(s2id_sp_formfield_subcategory).scope();
angular.element(javascript:void(0)).scope();
angular.element(select2-choice form-control).scope();
angular.element(select2-chosen).scope();
angular.element(select2-chosen-1).scope();
angular.element(sr-only).scope();
angular.element(select2-search-choice-close).scope();
angular.element(select2-arrow).scope();
angular.element(select2-focusser select2-offscreen).scope();
angular.element(subcategory).scope();
angular.element(snDisabled).scope();
angular.element(formModel.table).scope();
angular.element(formModel.sys_id).scope();
angular.element(getGlideForm()).scope();
angular.element({placeholder: field.placeholder}).scope();
angular.element(getEncodedRecordValues()).scope();
angular.element(sp_reference_element_sr_subcategory).scope();
angular.element(ng-isolate-scope select2-offscreen).scope();

 

 

 

angular.element("reference").scope();
angular.element("select2-container select2-reference select2-allowclear ng-isolate-scope ng-form-element").scope();
angular.element("s2id_sp_formfield_subcategory").scope();
angular.element("javascript:void(0)").scope();
angular.element("select2-choice form-control").scope();
angular.element("select2-chosen").scope();
angular.element("select2-chosen-1").scope();
angular.element("sr-only").scope();
angular.element("select2-search-choice-close").scope();
angular.element("select2-arrow").scope();
angular.element("select2-focusser select2-offscreen").scope();
angular.element("subcategory").scope();
angular.element("snDisabled").scope();
angular.element("formModel.table").scope();
angular.element("formModel.sys_id").scope();
angular.element("getGlideForm()").scope();
angular.element("{placeholder: field.placeholder}").scope();
angular.element("getEncodedRecordValues()").scope();
angular.element("sp_reference_element_sr_subcategory").scope();
angular.element("ng-isolate-scope select2-offscreen").scope();

 

 

I have already tried all options within the getElementsByName() I think because on the portal it is all angular the DOM route wont work as the Community pointed out in this thread 😞

Community Alums
Not applicable

Hi Andy

Did you find out a solution for this ?

 

Thanks