0
我正在創建聯繫表單。我想在我的輸入表單中使用幽靈文本,但將幽靈文本Javascript添加到我的代碼工作中,我的表單要求警報不再工作。表單需求警報,當我使用幽靈文本時不顯示
我認爲這是因爲代碼是讀取幽靈文本作爲表格被填充,而不是空的。我需要在人們沒有填充任何內容時顯示警報。
我認爲我需要製作它,所以幽靈文本沒有價值,但我不明白如何實現這一點。
這裏用一個形式要求我輸入字段的一個示例:
<label for='name' >Your Name *: </label
<input type='text' name='name' id='name' value='<?php echo $formproc->SafeDisplay('name') ?>' maxlength="50" /><br/>
<span id='contactus_name_errorloc' class='error'></span>
這裏是鬼文JS:
<script>// Reference our element
var txtContent = document.getElementById("name");
// Set our default text
var defaultText = "Full Name*";
// Set default state of input
txtContent.value = defaultText;
txtContent.style.color = "#CCC";
// Apply onfocus logic
txtContent.onfocus = function() {
// If the current value is our default value
if (this.value == defaultText) {
// clear it and set the text color to black
this.value = "";
this.style.color = "#000";
}
}
// Apply onblur logic
txtContent.onblur = function() {
// If the current value is empty
if (this.value == "") {
// set it to our default value and lighten the color
this.value = defaultText;
this.style.color = "#CCC";
}
}</script>
這裏是我的形式警報JS:
var frmvalidator = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your full name.");
這裏是窗體警報PHP:
//name validations
if(empty($_POST['name']))
{
$this->add_error("Please provide your full name.");
$ret = false;
}
也許我措辭,我的問題嚴重:/這個問題本身是沒有鬼的文本。問題是,我的表單要求不再顯示,因爲幽靈文本。該代碼正在讀取具有值的鬼文本。所以如果一個人在我的網站上,沒有填寫一個表示「姓名*」的表格,然後點擊「提交」,則顯示「請提供您的姓名」的提醒不會顯示。我需要弄清楚如何讓幽靈文本不會干擾表單提示。@ Michael Lapan – KateG