jQuery in Action, 2nd edition*
The moose likes HTML, CSS and JavaScript and the fly likes creating selectbox using jquery adding multiple selectboxes to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "creating selectbox using jquery adding multiple selectboxes to jsp" Watch "creating selectbox using jquery adding multiple selectboxes to jsp" New topic
Author

creating selectbox using jquery adding multiple selectboxes to jsp

chandra ganesh
Greenhorn

Joined: May 13, 2013
Posts: 6
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

Joined: May 26, 2003
Posts: 31076
    
233

What's a selectbox? That code adds options to a pull down select element.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating selectbox using jquery adding multiple selectboxes to jsp