The code example you included there from the Classic Designer is written using JQuery, and the Modern designer no longer natively includes JQuery support.
Additionally, the Javascript in the Modern designer runs within a sandboxed iFrame that doesn't have direct access to the form and fields in the way that the Classic designer did, so it can't target the form elements directly via the DOM like that.
The ability to manipulate fields and their contents in the Modern designer Javascript is all managed via the LFForm interface and its various functions, which are detailed in the help documentation (this link if you are self-hosted: https://doc.laserfiche.com/laserfiche.documentation/11/administration/en-us/Default.htm#../Subsystems/Forms/Content/Javascript-and-CSS/JavaScript-in-the-Forms-Designer.htm)
This code from the Classic Designer:
$('#q5 input').val('New Value');
Can be replaced by this code in the Modern Designer:
LFForm.setFieldValues({fieldId: 5}, "New Value");