I’m trying to dynamically set the recipient of my mailto link in javascript. I thought that I could just put a javascript variable in the recipient place of the link, but I get errors when trying to do so. Anyone have any suggestions of why this might not be working?
This is what I currently have, which is throwing errors inside my code.
JavaScript
x
5
1
var customerEmail = "someone@email.com";
2
3
<a href='mailto:' + customerEmail + '?subject=Quote&body=I%20would%20like%20to%20accept%20this%20quote' ><button>Click To Accept</button></a>
4
5
Advertisement
Answer
either pull out the concatenation out of the href or use bacticks
to fill the href.
JavaScript
1
4
1
<a href={`mailto:${customerEmail}?subject=Quote&body=I%20would%20like%20to%20accept%20this%20quote`} >
2
<button>Click To Accept</button>
3
</a>
4