2

Hi i am not good in javascript. This is a part of code from my ajax search auto-suggest and i need to replace "word" text with the text that comes from input. How can I do that?

<input type="text" id="selectedInput"/><ul id="list"></ul>    
<script>    
var keyword = "word";  (wrong code)      
url: "http://itunes.apple.com/search?term=" + keyword + "&entity=musicTrack",
..

See http://jsfiddle.net/coladeu/Qhj5N/3/

2
  • When do you want it? When the page loads? Or when an event occurs? Commented Sep 23, 2012 at 18:56
  • i want it when event occurs. when i type characters, to start show me the suggestions. i dont think is that hard but i am not good in js. Commented Sep 23, 2012 at 20:11

2 Answers 2

3

This will obtain the value in your textbox.

var keyword = document.getElementById('selectedInput').value;

Edit:

Just as an FYI, the same thing can be accomplished using jQuery:

$('#selectedInput').val();

Sign up to request clarification or add additional context in comments.

5 Comments

in jsfiddle demo jQuery is used, so it can be also var keyword = $('#selectedInput').val();
You can do exactly the same without jQuery which is, by the way, overkill for the browser and network traffic if you intend to use it only for traversing the DOM. document.querySelectorAll('#selectedInput').innerHTML
Oh didn't even check his jsfiddle.
thanks for your help but i need this code to work and show me the suggestions when i type words on the search box and it dont show.
Cola, that sounds like the basis for an entirely new question. This is how you would obtain the value in a input field. If you are now onto working through bugs in the ajax/server-side then I suggest you accept an answer for this one and open a new question that is focused on that issue.
1

You can use $('#selectedInput').val() here is an example

http://jsfiddle.net/Qhj5N/4/

3 Comments

nandu i check the link i am not see it working. it don't show results.
@Cola : sorry about that..updated the jsfiddle .. try this out.. jsfiddle.net/Qhj5N/22
the results work now but I am using chrome and i get popups for every character i type. can you make them disapear? I really apreciate your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.