只有当用户选中复选框并提交表单时,我才会下载PDF文件。现在PDF下载,只要他们选中复选框并点击提交按钮。表单提交无关紧要。主要问题是我仅限于Jquery或纯JavaScript。我无权访问后端文件。无论如何,有人知道这样做吗?该复选框不需要被要求。下面是代码我现在所拥有的:只有当复选框被选中并提交表格时才下载文件
$("#formid").submit(function(ev){
ev.preventDefault();
$.ajax({
url: 'processing.cfc', // background processing procedures
type: 'get',
dataType: 'json',
data: $("#formid input, #formid select").serialize(), //pass all present input variables
success: formReturn,
failure: function(){ alert("There was an error processing your request. \nPlease try again."); return false; }
});
var $choice = $(this).find("input[name='checkbox1']:checked");//get the selected option
if ($choice.length)// if an option is selected
window.open('http://whitepaper.com/info/whitepaper/WhyBuy_WhitePaper_FinalB.pdf') ;
var $choice2 = $(this).find("input[name='checkbox2']:checked");//get the selected option
if ($choice2.length)// if an option is selected
window.open('http://brochure.com/info/brochure/welcome-kit-brochure.pdf') ;
});
,这里是为复选框的HTML:
<div class="chkbox">
<input type="checkbox" class="regular-checkbox" name="checkbox1"
id="checkbox-1-1"><label for="checkbox-1-1"></label>
<span class="dld">Clayton Homes guide to buying a home</span>
</div>
<div class="chkbox">
<input type="checkbox" class="regular-checkbox" name="checkbox2"
id="checkbox-1-2"><label for="checkbox-1-2"></label>
<span class="dld">Why Clayton Homes brochure</span>
</div>
任何帮助表示赞赏。
感谢您的快速回复。除了最初的成功参数需要在那里的formReturn之外,这种方法才有效。我应该包含JavaScript验证,但它基本上处理所有的表单域。无论如何要把它包含在PDF文件中吗?再次感谢。 – UTvolfan85
在PDF文件中包含什么? html表单验证? –
不,包含AJAX Post的Success部分中的formReturn参数以及PDF下载。 – UTvolfan85