This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

creating selectbox using jquery adding multiple selectboxes to jsp

 
chandra ganesh
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am posting my jsp and jquery code

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!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">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<title>Insert title here</title>
<script type="text/javascript">
$(document).ready(function(){
$('#search').keyup(function() {

var search = $('#search').val();

if(search.length>2){
var s = $('<select />');
$.ajax({
type:"POST",
url: "searchuser",
cache:false,
data: 'search=' + $("#search").val() ,
success: function(response){

$.each(response, function (index, value) {
$('<option />', {value: value, text: value}).appendTo(s);
});

},
error: function(e){
alert('Error: ' + e);
}

});
}

s.appendTo('body');});
});
</script>

</head>
<body>


<form>
<input id="search" type="text" name="search" />
</form>
<div id="info"></div>

<div id="other">
Trigger the handler
</div>

</body>
</html>

and the above code is creating multiple selectboxes i understood that is due to ajax calls but how can i avoid creating additional selectboxes or suggest me how can i convert text box to selectbox
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34095
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a selectbox? That code adds options to a pull down select element.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic