In the following code I want to add a mailto link with the value of #text30
Please see the click_event at the end and can someone kindly advise what goes after the mailto?
import wixLocation from 'wix-location';
$w.onReady(function () { w('#text30').onMouseIn(()=>{removeUnderline();}); //removing the underline when hovering the text $w('#text30').onMouseOut(()=>{addUnderline();}); });
function removeUnderline(){
let oldHtmlStr = $w('#text30').html;
let newHtmlStr = oldHtmlStr.replace( /underline/i, 'none');
$w('#text30').html = newHtmlStr;
}
function addUnderline(){
let oldHtmlStr = $w('#text30').html;
let newHtmlStr = oldHtmlStr.replace( /none/i, 'underline');
$w('#text30').html = newHtmlStr;
}
export function text30_click(event) {
wixLocation.to("mailto:@newHtmlStr");
}
Hi there Lmarie,
I am very much a beginner and have been trying to figure out an answer to the same question you asked. If you haven't gotten an answer, I think I just figured it out. This is a code from my page where clicking a button in a repeater opens an email from a dataset with a subject from a dataset:
$w("#repeater1").onItemReady(function ($w, itemData, index) { $w('#button1').link = 'mailto:' + itemData.email + '?subject=' + itemData.emailSubject; })
So you add '?subject=' + your item data field
and that should send an email with a subject line from your dataset.
You can also do something like '?subject=Fill in the ' + itemData.blank if you only want to pull only one word or phrase into the subject line. So add a phrase within the quotes after the = and then whatever variable text you want, add it from the dataset.
I hope that helps, it just made my life much easier!
SOLVED!
Didn't take long haha!! Figured out that all I needed to was add the variable to the mailto info instead of the subject const...
export function dismissedRequests_itemReady($item, itemData, index) { // Set the contact button to create an email to the user whose request was dismissed. $item("#emailButton").onClick(() => { const subject = "Your Setlist Request - "; wixLocation.to(`mailto:${itemData.email}?subject=${subject}${itemData.session}`); }); }
Hey, is there a way to add a variable to the email subject?
I tried this:
export function dismissedRequests_itemReady($item, itemData, index) { // Set the contact button to create an email to the user whose request was dismissed. $item("#emailButton").onClick(() => { const subject = "Your Setlist Request - ${itemData.session}"; wixLocation.to(`mailto:${itemData.email}?subject=${subject}`); }); }
But as I suspected it didn't work haha. I'm guessing this is because it's within the quotations? But when I tried it like this
subject = "Your Setlist Request -" + ${itemData.session};
it just stopped the function from working
I'm sorry that will not be possible with a text element. However, user repeater's onReady function. You can use the .link property of a button to do the same. See code below:
Assuming the field key of the email field is 'email', you can add this code to inside the page's onReady function:
$w("#myRepeater").onItemReady(($item, itemData, index) => { $item("#myButton").label = itemData.email; $item("#myButton").link = "mailto:" + itemData.email + "?subject=Something%20Intersting"; });
Remember to replace the element IDs with your own.
Please note that with .link property, you don't need to add an onClick event to the button.
Good luck!
Thanks Sam. "Text 30" is an email in a repeater. I want that email which varies through each repeater to be the mailto. Do you know how to pull it in?
Hello.
You can see your text element to open a new email window when clicked as shown below:
export function text30_click(event) { wixLocation.to("mailto:a@b.com?subject=Something%20Intersting"); }
This is a modification from our API here.
Good luck!