0

Hi i have return url for JSON search. Now i would like to have a textfield. In which people can enter there search terms. And when pressed submit. I would like to go and run the search.

So far i have this code. the reading of the JSON works fine. Because when i fill in a complete url it show me the desired results. But i'am doing something incorrectly in building the URL form the basis url + search terms.

I would be great if someone could explain me what i am doing wrong.

document.getElementById('submit').onclick = function() {
 var urlFD = "http://domain.com/support/search/solutions.json?term=" + document.getElementById('txt_name').value);

  $.getJSON('urlFD', function(data) {
        var output="<ul>";
        for (var i in data) {
            output+="<li>" + data[i].title + "--" + data[i].desc+"</li>";
        }

        output+="</ul>";
        document.getElementById("placeholder").innerHTML=output;
  });

}
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>

<input type="text" id="txt_name"  />
<input type="button" name="submit" id="submit" value="Submit">

<div id="placeholder"> </div>


</body>
</html>

1 Answers1

0

Dont quote your variable!

$.getJSON(urlFD, function(data) {
tymeJV
  • 103,943
  • 14
  • 161
  • 157