[英]Input user name and email id and download pdf certificate with same name (name+emailid) from a folder
您能否更正下面的代碼,以便用戶輸入他的名字和電子郵件 ID,並且從 OOEcertificate 文件夾下載具有相同(名字和電子郵件 ID)的 PDF 證書
調用 JavaScript 函數 function myFunction() { var downloadUrl = document.getElementById("url").value; document.getElementById("downlod").href = '/ooecertificate' + downloadUrl + '.pdf'; } alert("You are Successfully Called the JavaScript function"); }
<div> <label>ENTER YOUR REGISTRATION ID:</label> <br> </br> <label>(Your registration id is your firstname+registered email id: for example if your name is SAMMY DIXIT and your registered email id is SAMMY.DIXIT@GMAIL.COM your REGISTRATION ID WILL BE: SAMMYSAMMY.DIXIT@GMAIL.COM </label> <input type="text" name="url" id="url" onkeyup="myFunction()"> <a href="/OOEcertificate" id="downlod" download><span>Download</span></a> </div> </div>
這是一個從您的代碼開始的演示,它將從輸入框 #url 獲取值,並將使用該值來組成 url 字符串,該字符串將用於將瀏覽器導航到 pdf 下載。
這種行為是通過我評論的window.location.href
獲得的,以使演示在這里工作。 它將代表它在控制台中顯示 url。
function downloadPdf(){ //fetch the registrationId from the input#url let registrationId = document.getElementById("url").value; //transform the registrationId string to lower case registrationId = registrationId.trim().toLowerCase(); const pdfUrl = `/ooecertificate/${registrationId}.pdf`; //this is the statement to redirect the browser to the wanted url //now commented because it wouldn't work here on the snippet //window.location.href = pdfUrl; //on its behalf I'm writing the url on console console.log(pdfUrl); }
label.fieldLabel{ display: block; margin-bottom: 1rem; } label.fieldDescription{ display: block; margin-bottom: 1rem; border: solid 1px gray; padding: 1em; } button{ cursor: pointer; }
<div> <label class="fieldDescription"> Your registration id is your firstname+registered email id:<br> For example..<br> if your name is SAMMY DIXIT and your registered email id is SAMMY.DIXIT@GMAIL.COM<br> your REGISTRATION ID WILL BE: <b>sammysammy.dixit@gmail.com</b> </label> <label class="fieldLabel">ENTER YOUR REGISTRATION ID:</label> <input type="text" name="url" id="url"> <button onclick="downloadPdf();">Download</button> </div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.