HTML assign variable to element name
P粉148782096
P粉148782096 2023-09-09 20:57:07
0
2
459

Is there a way to assign a variable to the element name so that I can access the element and change the value:

[% FOREACH field IN ['id','type','updatedt','lastcheckdt'] %]
    <div class="row col-md-3 col-sm-6">
        <dl class="details-dl">
            <label>[% field %]</label>
            <div class="details-dg">
                <dd name=[% field %] class="float-right">[% order.$field %]</dd>    
            </div>
        </dl>
    </div>
[% END %]

I can format the updated datetime:

let dt_formatted = convertDateFormat("[% order.updatedt %]");
$( "[name='updatedt']" ).val(dt_formatted);

Unfortunately, assigning [ % field %] to the name does not assign any value to the name:

<dd name=[% field %] class="float-right">[% order.$field %]</dd>

P粉148782096
P粉148782096

reply all(2)
P粉135799949

Use .html() instead of .val to access properties in

$( "[name='updatedt']" ).val(dt_formatted); --> wrong
$( "[name='updatedt']" ).htmtl (dt_formatted); --> correct
P粉258788831

Looks like you're missing quotes here:

<dd name="[% field %]" ...>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template