I have in my application an autocomplete input field. When jsp with this autocomplete input field opens I get error 'names' is undefined
in line <body onload="getNames(names)">
. This happens only in IE8,7,9. In Chrome and Firefox everything is fine. In controller I fetch user's names and surnames and write them in one string seperated with $
and then I send that string allUsersRoleUserAC
to jsp. Method getNames(names) splits that string and put them to var tags
.
Here is jsp code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin page</title>
<link rel="stylesheet" type="text/css" href="<%=response.encodeURL(request.getContextPath() + "/css/jquery-ui.css") %>" />
<link rel="Stylesheet" type="text/css" href="<%=response.encodeURL(request.getContextPath() + "/css/DOMAlert.css") %>" media="screen" />
<script type="text/javascript" src="<%=response.encodeURL(request.getContextPath() + "/JavaScript/DOMAlert.js") %>"></script>
<script type="text/javascript" src="<%=response.encodeURL(request.getContextPath() + "/JavaScript/jquery-1.8.2.js") %>"></script>
<script type="text/javascript" src="<%=response.encodeURL(request.getContextPath() + "/JavaScript/jquery-ui.js") %>"></script>
<script type="text/javascript">
var tags = new Array();
function getNames(names){
tags = names.value.split('$');
}
</script>
</head>
<body onload="getNames(names)" >
<form action="<%=response.encodeURL(request.getContextPath() + "/admin/deleteUser.html") %>" method="post">
<input id="names" type="hidden" value="${ requestScope['allUsersRoleUserAC'] }" />
<input name="korisnik" class="userSelectDeleteUser" value="ime prezime" onclick="this.value=''" id="autocomplete" />
<input class="izbrisiKorisnikaButtonPosition" id="buttonRightPart" type="button" value="Izbriši" />
</form>
<script type="text/javascript">
$( "#autocomplete" ).autocomplete({
source: function( request, response ) {
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" );
response( $.grep( tags, function( item ){
return matcher.test( item );
}) );
}
});
</script>
</body>
</html>