[英]How to disable a button until fields are filled with entries
我目前正在與一個使用 Wix 構建他們的網站的團隊合作。 我是 Wix 的新手,創建了一個新表單,我想禁用“注冊”按鈕,直到所有文本輸入字段都填滿條目並選中復選框。 我在研究 Wix 之類的 Javascript 時寫了一些代碼,但它對我不起作用。
let validationMessage = '';
//$w('#button8').disable();
let schName = $w('#schoolName').value;
let schAddress = $w('#schoolAddress').value;
let schCity = $w('#schoolCity').value;
let schState = $w('#schoolState').value;
let schEmail = $w('#schoolEmail').value;
let schRegNo = $w('#schoolRegNumber').value;
let schPhoneNo = $w('#schoolPhoneNumber').value;
let schWebsite = $w('#schoolWebsite').value;
let isCheckedBox = $w('#tNa').checked;
let regButton = $w('#button8');
$w.onReady(function () {
//TODO: write your page related code here...
// Checking to see if all fields have values. If not disable button until it does.
if ((schName.length && schAddress.length && schCity.length &&
schState.length && schEmail.length && schRegNo.length && schPhoneNo.length && schWebsite.length === 0) && !isCheckedBox) {
regButton.disable();
validationMessage += 'All fields must be filled!\n';
} else {
regButtion.enbaled;
regButton.onClick((event) => {
formSubmission(event);
});
}
});
我做錯了什么嗎? 我已經將 && 和 & 用於 if 語句,但它不起作用。
嘗試這個
$w.onReady(function () {
//TODO: write your page related code here...
regButton.onClick((event) => {
// Checking to see if all fields have values. If not disable button until it does.
if ((schName.length ===0 || schAddress.length ===0 || schCity.length ===0 ||
schState.length ===0 || schEmail.length ===0 || schRegNo.length ===0 || schPhoneNo.length ===0 || schWebsite.length === 0) || !isCheckedBox) {
validationMessage += 'All fields must be filled!\n';
} else {
formSubmission(event);
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.