Reputation: 839
I am working on a dao dto struts architecture - Basically i want to populate my dto on every change function in javascript . I am trying following code ---
function onchangefunction() {
var e = document.getElementById("userSelectList");
strUser = e.options[e.selectedIndex].text;
alert(strUser);
strUser.toString();
var x = document.getElementById("ToLB");
var option = document.createElement("option");
<%
String strUser = request.getParameter("strUser");
ArrayList < SkillSetDTO > skillsetlst = (ArrayList < SkillSetDTO > ) ConfigurationDAO.getInstance().getSkillSetList(strUser);
SkillSetDTO skillsetDTO = new SkillSetDTO();
for (int i = 0; i < skillsetlst.size(); i++) {
skillsetDTO = (SkillSetDTO) skillsetlst.get(i);
String skillSet = skillsetDTO.getSkillsets();
%>
option.text = "<%=skillSet%>";
try {
// for IE earlier than version 8
x.add(option, x.options[null]);
} catch (e) {
x.add(option, null);
}
<%
}
%>
}
Till alert(strUser) its works fine but not after that , What wrong is done here?
UPDATE--
Ok i got it , it wont work . Can anybody tell me How to resolve this code by using Ajax request , i have never used ajax request before... 1) Passing parameter strUser and Calling methord "getSkillSetList" in ConfigurationDAO so that it will populate DTO class and 2) getting back an arraylist to jsp from SkillSetDTO .
Upvotes: 0
Views: 856
Reputation: 39268
This won't work. You are trying to execute server side code inside your javascript. The server side code will run once - before the JavaScript runs (when the page renders initially), but will not rerun in the onchange method. It's possible to use server side code to aid in building the javascript dynamically, but you can't interact with it through JavaScript. If you need to interact with the server in your JavaScript code, you can do it via Ajax
Upvotes: 2