我想獲得一個隱藏字段(產品)價值在我的形式,並通過這種通過對感謝您網頁:如何使用Jquery獲取隱藏值?
<form action="" name="downloadform" id="downloadform" class="downloadform" method="post">
<div class="field">
<input name="name" type="text" id="name" class="input name" placeholder="Name..." />
</div>
<div class="field">
<input name="company" type="text" id="company" class="input company" placeholder="Company..." />
</div>
<div class="field">
<input name="tel" type="text" id="tel" class="input tel" placeholder="Telephone..." />
</div>
<div class="field">
<input name="email" type="text" id="email" class="input email" placeholder="Email Address..." />
</div>
<?php /*?><div class="field captcha">
<img class="captcha_input" src="/inc/captcha.php" />
<input name="captcha" type="text" id="captcha" class="input captcha" placeholder="Please enter characters...">
</div><?php */?>
<div class="field">
<div class="medium secondary btn"><input type="submit" name="Submit2" value="Send Request" class="btn" id="downloadbtn" /></div>
<input type="hidden" name="product" id="product" class="product" value="<?php echo $page[3]; ?>" />
<input type="hidden" name="antiSpam" id="antiSpam" />
</div>
</form>
我有一個給ajaxForm文件,如下所示:
var antiSpam = function() {
if (document.getElementById("antiSpam")) {
a = document.getElementById("antiSpam");
if (isNaN(a.value) == true) {
a.value = 0;
} else {
a.value = parseInt(a.value) + 1;
}
}
setTimeout("antiSpam()", 1000);
}
反垃圾郵件();
$(function() {
filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
$("#downloadbtn").click(function() {
var name = $("#name").val();
var company = $("#company").val();
var tel = $("#tel").val();
var email = $("#email").val();
var product = $("#product").val();
var antispam = $("#antiSpam").val();
if (name == "") {
$("#name").focus();
$("#name").val("");
$("#name").css({background:"#b72a18", color:"#fff"});
return false;
}
if (company == "") {
$("#company ").focus();
$("#company ").val("");
$("#company ").css({background:"#b72a18", color:"#fff"});
return false;
}
if (tel == "") {
$("#tel").focus();
$("#tel").val("");
$("#tel").css({background:"#b72a18", color:"#fff"});
return false;
}
if (!filter.test(email)) {
$("#email").focus();
$("#email").val("");
$("#email").css({background:"#b72a18", color:"#fff"});
return false;
}
if (product == "") {
$("#product").focus();
$("#product").val("");
$("#product").css({background:"#b72a18", color:"#fff"});
return false;
}
$('.downloadform').html('<center><img src="/images/ajax-loader.gif" style="padding:20px;"></center>');
var dataString = '&name=' + name + '&tel=' + tel + '&company=' + company + '&email=' + email + '&product=' + product + '&antispam=' + antispam + '&type=download';
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "/process.php",
data: dataString,
success: function() {
setTimeout(function() {
$('.downloadform').html('<p>Thank you for your enquiry, we will contact you shortly. <a href="/pdfs/">Download</a></p>');
}, 3500);
}
});
return false;
});
});
正如上面的最後一部分「謝謝您的垂詢,我們將盡快與您聯繫,我想獲得隱藏字段產品的價值?
'VAR ProductValue = $('#product')。val();' – Daan
如果產品被隱藏了,那麼爲什麼你要關注它並且改變CC'if(product ==「」){'?還要檢查控制檯的產品價值,看它是否有價值?另外,確保你的整個頁面中有一個單獨的元素。 –