Click here to Skip to main content
15,905,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am adding text box items in list box on click of add button,it is working but in between two items it is some space,the empty space considering as item.how to avid this using jquery.
here is my code

What I have tried:

function Addbook() {
var bkLst = $("#LstSignInAuthority");
if (bkLst !== "") {
$(document).ready(function () {
$('#btnAdd').click(function (e) {

var name = $("#Book_Name").val();
$('#LstSignInAuthority').
append($("<option></option>").
attr("value", name).
text(name));
$("#Book_Name").val("");
$("#Title").val("");
$("#Book_Category_Name").val("");

});
});


}

}
Posted
Updated 3-Mar-16 20:41pm
Comments
[no name] 4-Mar-16 0:19am    
Provide an example what is your value in your textbox and what are the items you need to add in list.
Hussain Javed 4-Mar-16 0:44am    
I want to add books to list box by click each book which i get from pop up box
the text box value is book name that name will add to list box on click of add button
[no name] 4-Mar-16 1:02am    
As we are not sure about how textbox value looks like and you don't want add space in listbox, so for that provide an example.
Hussain Javed 4-Mar-16 1:06am    
for example,any book name is there is text box and add button is there
on click of add button the book name is should added to listbox
Hussain Javed 4-Mar-16 1:11am    
how can i send you my screen shot image to you

1 solution

var newValue = $('input[name=Book_Name]').val();
JavaScript
$('#LstSignInAuthority').append('<option value="' + newValue + '">' + newValue + '</option>');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900