Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have one search box ,in that search json data should append.

here is my html code

 <input type="search" id="merchantName" name="merchant" placeholder="enter merchant name"></input>

I have json data which contains merchant name. I want to append this merchant name on this search box in list form.how can I do..?this is my js function but here data is not appended in search box.

$(responseObj.merchants).each(function() {

    var output = "<ul><li>" + this.merchantName + " " +"</li></ul>";
    $('#list').append(output);

});
share|improve this question
    
What is #list??? Please improve your question, posting more of relevant code. What about a jsfiddle? BTW, you should use $.each() not $.fn.each() –  A. Wolff 19 hours ago
    
What type is responseObj.merchants ? Is it an array of json-objects? –  Homungus 19 hours ago
    
<ul data-role="listview" id="list" ></ul> and @homungus..yes its the array of json object containing merchant name ,as of now after clicking on search button i m gettint output as .xyz.com and xyz.co.in but i want this output should come only in that search filter box. –  user3415421 19 hours ago
add comment

2 Answers

Try this, if responseObj.merchants is an array:

for (var i = 0; i < responseObj.merchants.length; i++) {
    var output = "<li>" + responseObj.merchants[i].merchantName + " " +"</li>";
    $('#list').append(output);
}
share|improve this answer
    
i m getting output in list form already but i want same should only be appended in that search box..how can i ..?hope u understood.. –  user3415421 19 hours ago
    
you want to append the list of merchant-names to the input-field? the text of the input field should be the list? what do you mean? –  Homungus 19 hours ago
add comment

This should work or the other approach would be use for loop

$.each( responseObj.merchants function(index, value){
    var output = "<ul><li>" + value + " " +"</li></ul>";
    $('#list').append(output);
})

Explanation: For each merchant value we iterate over its value and append it to the output list.

But always, API documentation read is a must. The page contains examples and explanation to what you need.

http://api.jquery.com/jquery.getjson/

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.