多个选择值警报半值

时间:2013-08-06 06:35:29

标签: javascript multi-select

我希望Javascript提醒整个员工姓名(名字和姓氏),但是使用此代码,它只出于某种原因显示名字。关于如何解决这个问题的任何想法?

这是我的代码:

if ( $even1 % 2) 
    echo "<option value=". $employee_firstname . " " . $employee_lastname . ">". $employee_firstname . " " . $employee_lastname . "</option>";
else
    echo "<option value=". $employee_firstname . " " . $employee_lastname . ">". $employee_firstname . " " . $employee_lastname . "</option>";

javascript:

var List = document.getElementById('slcEmp');
var x = 0;

for (x = 0; x < List.length; x++) {
    if (List[x].selected) {
        alert(List[x].value);
    }
}

1 个答案:

答案 0 :(得分:0)

您需要将属性值放在引号中,因为它包含空格:

echo "<option value='". htmlentities($employee_firstname) . " " . htmlentities($employee_lastname) . "'>". $employee_firstname . " " . $employee_lastname . "</option>";
                    ^                                                                                 ^

如果名称包含特殊字符(例如htmlentities()),您还应该使用O'Leary