I'm currently working on a datalist/drop-down menu. The user can select an option in the datalist/drop-down menu and afterwards click on a save button to save the selected option into the database. I'm currently being tasked to create a button that copies the selected option and paste it into another datalist/drop-down menu with the same options as the previous one.
In order to do that I thought it would be best to see what information is being stored when an user save a selected option. I put a console.log command into the save button to see what data is being send.
I'm currently searching for a way to save the console.log output so that I can paste it into the other datalist/drop-down menu.
HMTL:
<button (click)="copyMessage('copyPaste02()')" value="click to copy" >Copy this</button>
Typescript:
copyPaste02() {
console.log(new Date);
}
copyMessage(val: string){
const selBox = document.createElement('textarea');
selBox.style.position = 'fixed';
selBox.style.left = '0';
selBox.style.top = '0';
selBox.style.opacity = '0';
selBox.value = val;
document.body.appendChild(selBox);
selBox.focus();
selBox.select();
document.execCommand('copy');
document.body.removeChild(selBox);
}
As one could guess, I'm currently copying the name of the function that does the console.log rather than the output of the console.log itself.
Could anyone please tell me how to fix this or tell me where I can find documentation that explains how to copy a selected option in a datalist.