データの表示にはajaxを使用しています。ドロップボックスから名前を選択すると ajax を使用し、選択した名前のデータが表示されます。これには次のスクリプトを使用します。
<script>
$(document).ready(function(){
$('#absentEmployeeName').change(function(){
alert($(this).val());
var absentEmployeeName = ($(this).val());
alert("hi");
if ($(this).val() != '') {
$.ajax({
url : '${sendEmpNameResourceURL}',
data : {
<portlet:namespace />absentEmployeeName : $(this).val()
},
type: 'POST',
dataType : "json",
success : function(jsonArray) {
alert(jsonArray);
$('#myUniqueLabelId').html( jsonArray[0]+ jsonArray[1] + jsonArray[2]);
}
});
}
});
});
</script>
ここ で、 absentEmployeeNameは、ajax を使用して情報が表示される名前を選択するドロップボックスの ID です。
私が今やりたいことは、 dropbox から名前を選択することに加えて、日付も選択したいです。選択した日付と名前(ドロップボックスから)に基づいて、データを表示したいと思います。データを表示できるように、(ドロップボックスと日付の) 両方の ID を serveresource 関数に渡すにはどうすればよいですか?
上記のスクリプトでは:
$('#absentEmployeeName').change(function()
ドロップボックスのみのIDを渡しています。2 つのフィールドの ID を渡す方法は?
編集:
ここに私のHTMLのスニペットがあります:
<script>
$(document).ready(function(){
$('#absentEmployeeName').change(function(){
alert($(this).val());
var absentEmployeeName = ($(this).val());
alert("hi");
if ($(this).val() != '') {
$.ajax({
url : '${sendEmpNameResourceURL}',
data : {
<portlet:namespace />absentEmployeeName : $(this).val()
},
type: 'POST',
dataType : "json",
success : function(jsonArray) {
alert(jsonArray);
$('#myUniqueLabelId').html( jsonArray[0]+ jsonArray[1] + jsonArray[2]);
}
});
}
});
});
</script>
<body>
<select id="absentEmployeeName" name="absentEmployeeName" >
<%List<Employee> EmpList = EmployeeLocalServiceUtil.getEmployees(-1,-1);
List<LeaveCard> leaveBalList = LeaveCardLocalServiceUtil.getLeaveCards(-1,-1);
for(Employee emp : EmpList ) {
long empId = emp.getEmpId();
%>
<option value='<%=emp.getEmpId() %>' name = "leaveEmp"><%=emp.getEmpFname()%> <%=emp.getEmpLname()%></option>
<%} %>
</select>
<div id = "empDetails">
</div>
<input type = "date" id = currentDate/>
<td colspan=2>
<input type="radio" name="forcedabsent" value="LWP">To be treated as LWP
<input type="radio" name="forcedabsent" id = "absenteeEmp"> <label id="myUniqueLabelId"></label> to apply for leave<br><br>
<b>Other instructions to Employee/HR</b><br>
<textarea cols=60 rows=3 name = "markAbsentRemarks" id = "markAbsentRemarks"> </textarea>
</td>
</body>