I need to set a value of the textbox using a JAVASCRIPT function after the page has been rendered. I tried by getting an ID of the textbox, but it keeps on changing on every load. Is there any possible way to set the value of text box? It's likely I'm creating like an extension which I need to set the value of input and select field.
I tried Queryselctor. example :
getElementsByTagName('input')1.value = "testRecord";
It sets the value of last name in contact form and feels like it worked. When I click on save, it just empty it and showing as mandatory! But when i type some thing in textbox and then i use my function to set value, it worked.
This is the code generated by sales force.
<div data-aura-rendered-by="14996:0" class="uiInput uiInputText uiInput--default uiInput--input" data-aura-class="uiInput uiInputText uiInput--default uiInput--input">
<label class="uiLabel-top form-element__label uiLabel" for="14981:0" data-aura-rendered-by="14991:0" data-aura-class="uiLabel">
<span class="" data-aura-rendered-by="14992:0">Last Name</span>
<!--render facet: 14994:0-->
<span class="required " data-aura-rendered-by="14982:0">*</span>
</label>
<input class="compoundBLRadius compoundBRRadius form-element__row input" maxlength="80" type="text" aria-describedby="" placeholder="Last Name" required="" id="14981:0" data-aura-rendered-by="14985:0" data-interactive-lib-uid="242" aria-required="true">
</div>
I have attached Images for your reference.
Setting value of textbox from console
Value successfuly set in text box.
After clicking save button, the textbox fild become empty and shows mandratory error!
Thanks in advance.