0
我有一個名稱和電子郵件字段的基本新聞信函表格。我希望表單在用戶提交表單後隱藏。只有驗證過程沒有任何錯誤時,它才應該隱藏。這裏是我的代碼隱藏提交後的新聞信函表
HTML
<div class="form-row">
<div class="col-lg-12">
<input type="text" name="name" id="name" value="" class="form-control" placeholder="Your Name">
</div>
<div style="clear:both;"></div>
<div class="col-lg-12">
<input type="text" id="email" name="email" value="" class="form-control" placeholder="Your Email">
</div>
<div style="clear:both;"></div>
<div class="col-lg-12">
<input type="submit" id="submit" name="submit" value="Sign up" class="btn-primary">
</div>
</div>
驗證
<script language="Javascript" type="text/javascript">
<!--
/* wording of your error and thank you messages */
var error_1="Please enter your valid email address";
var error_2="Please enter your name";
var thankyou="Thank you. We'll keep you interested.";
function trim(str){str = str.replace(/^\s*$/, '');return str;}
function $Npro(field){var element = document.getElementById(field);return element;return false;}
function emailvalidation(field, errorMessage) {
var goodEmail = field.value.match(/[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/);
apos=field.value.indexOf("@");dotpos=field.value.lastIndexOf(".");lastpos=field.value.length-1;tldLen = lastpos-dotpos;dmLen=dotpos-apos-1;var badEmail= (tldLen<2 || dmLen<2 || apos<1);
if (!goodEmail || badEmail) {$Npro("Error").innerHTML=errorMessage;$Npro("Error").style.display="inline";field.focus();field.select();return false;}
else {return true;}
}
function emptyvalidation(entered, errorMessage) {
$Npro("Error").innerHTML="";
with (entered) {
if (trim(value)==null || trim(value)=="") {/*alert(errorMessage);*/$Npro("Error").innerHTML=errorMessage;$Npro("Error").style.display="inline";return false;}
else {return true;}}//with
}//emptyvalidation
function signup(thisform) {
with (thisform) {
if (emailvalidation(email,error_1)==false) {email.focus(); return false;};
if (emptyvalidation(name,error_2)==false) {name.focus(); return false;};
}
$("#submit, #myResponse").hide(); // Hide the buttom and the message
$("#loading").show(); // show the loading image.
params=$("#subform").serialize();
$.post("optIn.php", params, function(response){
//alert(response); //may need to activate this line for debugging.
$("#loading").hide();
$("#myResponse").html(thankyou); //Writes the "Thank you" message that comes from optIn.php and styles it.
$('#myResponse').css({display:'inline',color:'green'})
$("#submit").show();
}
)
return false;
}
//-->
</script>
請幫助,因爲我有這個認識非常有限。