简体   繁体   English

从 Javascript 创建填充的 email

[英]Creating Populated email from Javascript

I want to start off by saying I have no idea what I am doing with HTML and Javascript but I am trying to learn.我想首先说我不知道我在用 HTML 和 Javascript 做什么,但我正在努力学习。 What I am creating will not be hosted by any server, it is more of a HTML web form(I think that is what i would call it) for employees to fill out and create a standardized email.我正在创建的内容不会由任何服务器托管,它更像是 HTML web 表格(我认为这就是我所说的),供员工填写并创建标准化的 Z0C83F57C786A0B4A39EFAB23731CEBC7. I have 97% of it working but need a little help with the last part.我有 97% 的工作,但在最后一部分需要一点帮助。 Below is the Javascript that works:以下是有效的 Javascript:

function populateEmail() { 
    
    let bl = document.getElementById("blurb").value;
    let a = document.getElementById("reg").value;
    let b = document.getElementById("lvl").value;
    let c = document.getElementById("node").value;
    let i = document.getElementById("cust").value;

    let d = document.getElementById("rea").value;
    let e = document.getElementById("ma").value;
    let f = document.getElementById("start_dt").value.replace("T", " ");

    let g = document.getElementById("poc").value;
    let h = document.getElementById("appr").value;

    let m_to = "DL-ListOne; DL-ListTwo; DL-ListThree"
    let m_cc = "DL-ListFour; DL-ListFive;"
    
    let today = new Date();
    let dd = String(today.getDate()).padStart(2, '0');
    let mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    let yyyy = today.getFullYear();
    today = mm + '/' + dd + '/' + yyyy;
    
    let notify = document.getElementById("notify_lvl").value;
    
    if (notify == "Initial"){
        let deap = "Activation ";
    }
    else if (notify == "Update"){
        let deap = "Update ";
    }
    else{
        let deap = "De-Activation ";
    }

    document.location.href = "mailto:" + encodeURIComponent(m_to) + "?cc=" + encodeURIComponent(m_cc)
    + " &subject=DEAP " + encodeURIComponent(b) + ": Any Region " + today
    + " "
    + "&body=" 
    + "%0D%0A%0D%0A"
    + encodeURIComponent(bl) + "%0D%0A%0D%0A"
    + "Name: " + encodeURIComponent(a) + "%0D%0A"
    + "Activation – (" + encodeURIComponent(b)
    + "Current Impact = " + encodeURIComponent(c) + " modules, " + encodeURIComponent(i) + " customers) %0D%0A"
    + "Reason: " + encodeURIComponent(d) + "%0D%0A"
    + "Event Geographical Area: " + encodeURIComponent(e) + "%0D%0A"
    + "Event Start: " + encodeURIComponent(f) + "%0D%0A"
    + "POC: " + encodeURIComponent(g) + "%0D%0A"
    + "Approved by: " + encodeURIComponent(h) + "%0D%0A"

}

Now when I try and add the Variable deap to the subject line it stops creating the email.现在,当我尝试将变量deap添加到主题行时,它会停止创建 email。 Here are the different ways I have tried to add it.这是我尝试添加它的不同方法。

+ " &subject=DEAP " + deap + encodeURIComponent(b) + ": NE Region " + today

+ " &subject=DEAP " + encodeURIComponent(deap) + encodeURIComponent(b) + ": NE Region " + today

then I thought that maybe I had to add some text or space in there to have it take affect so I tried adding + " " + after the variable deap然后我想也许我必须在其中添加一些文本或空格才能使其生效所以我尝试在变量deap之后添加+ " " +

I am trying to keep the post to a minimum, if you need my ugly looking HTML I will be happy to post it but I am still trying to figure out how to load div from Javascript so my code isn't DRY.我试图将帖子保持在最低限度,如果你需要我的丑陋 HTML 我会很乐意发布它,但我仍在试图弄清楚如何从 Javascript 加载div ,所以我的代码不是 DRY。

Thank you in advance for your time提前感谢您的时间

It's because you're declaring deap inside your if statements:这是因为您在if语句中声明deap

 if ('notify' == "Initial") { let deap = "Activation "; } else if ('notify' == "Update") { let deap = "Update "; } else { let deap = "De-Activation "; } console.log(deap);

If you declare it outside and reassign it inside your if blocks, it should work:如果你在外面声明它并在你的if块内重新分配它,它应该可以工作:

 let deap; if ('notify' == "Initial") { deap = "Activation "; } else if ('notify' == "Update") { deap = "Update "; } else { deap = "De-Activation "; } console.log(deap)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM