我正在爲我的JavaScript類做一個表單,並且我被卡住了它的某個部分。我有一個單獨的驗證器JavaScript文件,並調用該HTML文件的功能。所有的驗證工作,如果表單區域未填寫。我想要做的是,如果字段留空,他們將無法驗證,並將值插入該字段。下面是表單字段的示例,html頁面中的javascript函數以及外部驗證器js文件。在HTML頭驗證後的Javascript填充表格
通話功能:
function formvalidation(thisform) {
with (thisform) {
if (textbox_validation(first_name,"Please enter your first name.")==false)
{first_name.blur(); return false;};
if (textbox_validation(business_name,"Please enter your business. Please enter N/A if
you do not have one.")==false) { business_name.focus(); return false;
business_name.value=="N/A";};
外部JS驗證:
function textbox_validation(entered, alertbox) {
with (entered) {
if (value==null || value=="") {
alert(alertbox);
return false;
}
else {
return true;
}
}
}
因此驗證工作,重點是空字段,但是對於我的一些領域我他們想如果驗證失敗或者如果它沒有填充int,則填充一定的值。 business_name行代碼是當我試圖使其工作。任何幫助深表感謝!
通常不鼓勵使用'with'。資料來源:http://www.yuiblog.com/blog/2006/04/11/with-statement-considered-harmful/ – Halcyon