asked on
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Sample User Registration</title>
<script language="javascript" src="js/Users.js"> </script>
</head>
<body atload="findActiveUsersRequest(findActiveUsers)">
<H2>User Registration</H2>
<div id="userAccessForm" >
<form name="userAccessForm" id="userAccessForm">
<div id="userAccessResults" style=" width : 364px; float:left;"></div><br> <table width="100%" border="1px">
<tr><td> <p>Organisation *<br>
<select name="UserID" id="UserID"> <option value="Choose your Organisation" selected>Choose Username</option>
<option value="1">Dynamically populate User1</option> <option value="2">Dynamically populate User2</option> <option value="3">Dynamically populate user3</option> </select> </p><td>
<input name="submit" type="submit" id="submit" value="Submit"> <input name="reset" type="reset" id="cancel" value="Cancel">
</td></tr>
<tr><td>
<div id="UserResults" style=" width:353px; float:left;"></div></td></tr>
</table>
</form></body>
</html>
function findActiveUsersRequest(findActiveUsers){
var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
var returnText = xmlhttp.responseText;
document.getElementById("UserResults").innerHTML=returnText;
};
var loadingHtml = "<img border=\"0\" src=\"images/busy.gif\" width=\"50\" /> Active Users Details...";
document.getElementById("UserResults").innerHTML=loadingHtml;
xmlhttp.open("GET","mets?action=users&userAction="+findActiveUsers);
xmlhttp.send();
}
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
public class RequestActionFactory {
@SuppressWarnings("unchecked")
public static Action getAction(HttpServletRequest request) {
// Retrieve action parameters
String action = request.getParameter("action");
String userAction = request.getParameter("UserAction");
// Validate
if (action != null) {
// Event request
if (action.equals("users")) {
List<UserIdDTO> userDTOList = getActiveUsers(); //Gets the UserIds from the DB
StringBuffer[] stringBuffer = new StringBuffer[userDTOList.size()];
for (UserIdDTO userDTO : userDTOList) {
for(int i=0; i<userDTOList.size(); i++) {
stringBuffer[i] = new StringBuffer();
stringBuffer[i].append(responseValue(userDTO));
}
}
sendResponse(response.getWriter(), stringBuffer);
}
}
return null;
}
private StringBuffer responseValue(UserIdDTO userDTO){
StringBuffer strBuffer = new StringBuffer();
strBuffer.append(userDTO.getId());
strBuffer.append(" - ");
strBuffer.append(userDTO.getuserName());
return strBuffer;
}
public static void sendResponse(PrintWriter writer, StringBuffer[] stringBuffer) {
if (stringBuffer != null) {
for(int i=0; i<stringBuffer.length; i++) {
if(null!=stringBuffer[i]) {
writer.write(stringBuffer[i].toString());
}
}
} else {
// TODO write to log
}
}
}
xmlhttp.onreadystatechange = function() {
var returnText = xmlhttp.responseText;
document.getElementById("UserResults").innerHTML=returnText;
};
function selectAccount() {
var myarray = ["1-john.Smith","2-Adam.smith","3-Peter.smith"];
var result = "<select name='results'/>";
for (var key in myarray) {
result += "<option value="+myarray[key].split("-")[0]+">"+myarray[key].split("-")[1]+"</option>";
}
document.getElementById("results").innerHTML=result;
}
</head>
<body onload='selectAccount()'>
<div id='results'></div>
</body>
ASKER
ASKER
for (UserIdDTO userDTO : userDTOList) {
for(int i=0; i<userDTOList.size(); i++) {
stringBuffer[i] = new StringBuffer();
stringBuffer[i].append("["+responseValue(userDTO)+"],");
}
}
stringBuffer.toString().substring(stringBuffer.length-1);
ASKER
xmlhttp.onreadystatechange = function() {
var returnText = xmlhttp.responseText;
//first check here how the returnText is coming......
var result = "<select name='results'/>";
for (var key in myarray) {
result += "<option value="+myarray[key].split("-")[0]+">"+myarray[key].split("-")[1]+"</option>";
}
document.getElementById("UserResults").innerHTML=returnText;
};
["1-john.Smith","2-Adam.smith","3-Peter.smith"];
ASKER
ASKER
var result = "<select name='results'>";
for (var key in myarray) {
result += "<option value="+myarray[key].split("-")[0]+">"+myarray[key].split("-")[1]+"</option>";
}
result +="</select>";
document.getElementById("UserResults").innerHTML=result;
ASKER
ASKER
ASKER
var result = "<select name='results'>";
for (var key in properText) {
alert("The Key with Proper is:" +properText[key]);
alert("The Key without Proper is:" +key);
result += "<option value="+properText[key].split("-")[0]+">"+properText[key].split("-")[1]+"</option>";
}
result +="</select>";
alert("The result is: " + result);
ASKER
StringBuffer[] stringBuffer = new StringBuffer[userDTOList.size()];
for (UserIdDTO userDTO : userDTOList) {
for(int i=0; i<userDTOList.size(); i++) {
stringBuffer[i] = new StringBuffer();
stringBuffer[i].append(responseValue(userDTO));
i++;
}
}
sendResponse(response.getWriter(), stringBuffer);
}
private StringBuffer responseValue(UserIdDTO userDTO){
StringBuffer strBuffer = new StringBuffer();
strBuffer.append(userDTO.getId());
strBuffer.append(" - ");
strBuffer.append(userDTO.getuserName());
return strBuffer;
}
public static void sendResponse(PrintWriter writer, StringBuffer[] stringBuffer) {
if (stringBuffer != null) {
for(int i=0; i<stringBuffer.length; i++) {
if(null!=stringBuffer[i]) {
writer.write(stringBuffer[i].toString());
}
} else {
// TODO write to log
}
ASKER
for (var key in properText) {
alert("The Key with ProperText is:" +properText[key]);
alert("The Key without ProperText is:" +key);
ASKER
ASKER
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.
TRUSTED BY