-1

I am trying to dynamically set a cell id using a cnt counter variable. However, instead of a number, I get the cnt word when viewing page source in browser.

What is wrong

 q1TargetVolume.setAttribute('id', `q1TargetVolume-${cnt}`);  
user1082748
  • 365
  • 1
  • 7
  • 18
  • 1
    [Can't reproduce](https://jsfiddle.net/uhmay5hx/). Please show a [mcve]. – JJJ Dec 13 '17 at 14:38
  • 1
    dataRowCell4 = dataRow.insertCell(2); q1TargetVolume = document.createElement("input"); q1TargetVolume.setAttribute('type', 'text'); q1TargetVolume.setAttribute('maxlength', '8'); q1TargetVolume.setAttribute('size', '4'); q1TargetVolume.setAttribute('id', `q1TargetVolume-${cnt}`); q1TargetVolume.setAttribute('value', record.get('q1_target_volume__c')); dataRowCell4.appendChild(q1TargetVolume); – user1082748 Dec 13 '17 at 14:48
  • in my code, there are ticks which are removed here – user1082748 Dec 13 '17 at 14:49

1 Answers1

1

I guess you wish to append a count value to the string q1TargetVolume-, and use it as the id for an element. You can try this method.

q1TargetVolume.setAttribute( 'id', 'q1TargetVolume-' + cnt );//cnt is the count value you wish to append
HariV
  • 687
  • 1
  • 10
  • 17