I have a new form for a SharePoint list. this form should set some value through code. I'm using SharePoint on-premises 2019 designer new form.
HTML code of the new form element:
<tr style="visibility: hidden;">
<td width="190px" valign="top" class="ms-formlabel">DStatus</td>
<SharePoint:FormField runat="server" id ="ff32{$Pos}" ControlMode = "New" FieldName="DRStatus" __designer:bind="{ddwrt:DataBind('u',concat('ff32',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@DRStatus')}"/>
<SharePoint:FieldDescription runat="server" id = "ff32description{$Pos}" FieldName="DRStatus" ControlMode="New"/>
</td>
</tr>
JS code to set value:
var status = $('#Lookup id');
var statusOption = status.find('option:eq(1)');
var selectedStatus;
selectedStatus= statusOption.text();
alert("DRStatus: " +selectedStatus);
$("input[Title='DRStatus']").val(selectedStatus);
I have tried the approach below. It can extract the values if the column was a lookup. But cannot set/save the value for the column element in list.
Please help, how can I set the column element value directly through code without using workflow?