我正在创建一个简单的表单,如果正在填充“隐藏”字段,则会发出警报,但我看不到我错过的内容或我错误的语法:
<form method="post" action="http://www.URL/form.php?form=159" id="frmSS159" onsubmit="return CheckForm159(this);">
<input type="text" name="email" value="Email Address" onclick="this.value='';" onBlur="if(this.value=='')this.value='Email Address';" />
<div style="padding: 5px 0;" aria-hidden="true">
<input type="text" name="asdf" tabindex="-1" value="" placeholder="If content, alert error">
</div>
<input type="submit" value="Subscribe" />
</form>
function CheckForm159() {
if ($_POST['asdf'] != '') {
alert("Please type your email address instead of using a form-filler");
}
return true;
}
答案 0 :(得分:1)
您的代码中有错误... 你在JavaScript中添加了$ _POST这是PHP语法。
您的更新代码......
<script>
function CheckForm159() {
var _curValue = document.getElementById('asdf').value;
if (_curValue != '') {
alert("Please type your email address instead of using a form-filler");
}
return true;
}
</script>
<form method="post" action="http://www.URL/form.php?form=159" id="frmSS159" onsubmit="return CheckForm159(this);">
<input type="text" name="email" value="Email Address" onclick="this.value='';" onBlur="if(this.value=='')this.value='Email Address';" />
<div style="padding: 5px 0;" aria-hidden="true">
<input type="text" id="asdf" name="asdf" tabindex="-1" value="" placeholder="If content, alert error">
</div>
<input type="submit" value="Subscribe" />
</form>
答案 1 :(得分:0)
只需使用JQuery中的onChange函数即可。输入更改后,它将显示警告,如此。
$("input[name=asdf").change(function(){
alert("Input value changed!");
});