如何在全名构建的中间首字母后添加句点

时间:2018-09-28 17:20:04

标签: adobe-javascript

我正在尝试从三个字段(First,MI和Last)建立全名。如果中间的初始字段为空白,则我不想在组合名称中出现句号。我的代码在下面,并且MI字段为空白时,名字和姓氏之间仍会出现一个句点。在这种情况下,partial_name不会被应用。

    // Get field values 
var F_Name = this.getField('First_Name').value; 
var M_Name = this.getField('MI').value; 
var L_Name = this.getField('Last_Name').value; 

// Build full_name string
var full_name = F_Name + " " + M_Name +  ". " + L_Name;

// Build Partial Name string
var partial_name = F_Name + " " + L_Name;
 
if(M_Name="") {event.value = partial_name;
}
else {event.value = full_name;
}

screen capture of error

1 个答案:

答案 0 :(得分:-1)

    // Get field values 
var F_Name = this.getField('First_Name').value; 
var M_Name = this.getField('MI').value; 
var L_Name = this.getField('Last_Name').value; 

// Build full_name string
var full_name = F_Name + " " + M_Name +  ". " + L_Name;

// Build Partial Name string
var partial_name = F_Name + " " + L_Name;
 
if(this.getField('MI').value=="") {
event.value = partial_name; 

// I think that's because you used single (=) instead of (==) or (===) and you //wrote If with a capital I 

}
else {event.value = full_name;
}