Primero, aquí está el código javascript.
const nameId = calledVariable.value // This variable is an input from a form // Create the button var payButton = document.createElement('input'); payButton.setAttribute('type', 'button'); payButton.setAttribute('value', 'UNPAID'); payButton.setAttribute('class', 'unpaidButton'); payButton.setAttribute('id', nameId); // This needs to be text of input payButton.setAttribute('onClick', 'updateButton(this.id)');y este es el resultado HTML
<input type="button" value="UNPAID" class="unpaidButton" id="" onclick="updateButton(this.id)"> ¿Cómo hago para que HTML/javascript reconozca nameId como su valor?
No necesita usar ${...} para pasar el valor de var a la función setAttribute. Use solo el nombre de la variable. Como eso:
const nameId = 123; const payButton = document.querySelector('button'); console.log('before', payButton) payButton.setAttribute('id', nameId); const check = document.querySelector('button'); console.log('after',check) <button>button</button>Y resolví mi propia pregunta... use lo siguiente en el código...
payButton.setAttribute('id', `${nameId}`);Este es un momento Facepalm...